MCPcopy Index your code
hub / github.com/ipython/ipython / dict_dir

Function dict_dir

IPython/utils/wildcard.py:58–73  ·  view source on GitHub ↗

Produce a dictionary of an object's attributes. Builds on dir2 by checking that a getattr() call actually succeeds.

(obj)

Source from the content-addressed store, hash-verified

56 return show_all or str.startswith("__") or not str.startswith("_")
57
58def dict_dir(obj):
59 """Produce a dictionary of an object's attributes. Builds on dir2 by
60 checking that a getattr() call actually succeeds."""
61 ns = {}
62 for key in dir2(obj):
63 # This seemingly unnecessary try/except is actually needed
64 # because there is code out there with metaclasses that
65 # create 'write only' attributes, where a getattr() call
66 # will fail even if the attribute appears listed in the
67 # object's dictionary. Properties can actually do the same
68 # thing. In particular, Traits use this pattern
69 try:
70 ns[key] = getattr(obj, key)
71 except AttributeError:
72 pass
73 return ns
74
75def filter_ns(ns, name_pattern="*", type_pattern="all", ignore_case=True,
76 show_all=True):

Callers 1

list_namespaceFunction · 0.85

Calls 1

dir2Function · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…