MCPcopy Create free account
hub / github.com/ipython/traitlets / getmembers

Function getmembers

traitlets/traitlets.py:241–258  ·  view source on GitHub ↗

A safe version of inspect.getmembers that handles missing attributes. This is useful when there are descriptor based attributes that for some reason raise AttributeError even though they exist. This happens in zope.interface with the __provides__ attribute.

(object: t.Any, predicate: t.Any = None)

Source from the content-addressed store, hash-verified

239
240
241def getmembers(object: t.Any, predicate: t.Any = None) -> list[tuple[str, t.Any]]:
242 """A safe version of inspect.getmembers that handles missing attributes.
243
244 This is useful when there are descriptor based attributes that for
245 some reason raise AttributeError even though they exist. This happens
246 in zope.interface with the __provides__ attribute.
247 """
248 results = []
249 for key in dir(object):
250 try:
251 value = getattr(object, key)
252 except AttributeError:
253 pass
254 else:
255 if not predicate or predicate(value):
256 results.append((key, value))
257 results.sort()
258 return results
259
260
261def _validate_link(*tuples: t.Any) -> None:

Callers 2

setup_classMethod · 0.85
trait_eventsMethod · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…