MCPcopy Index your code
hub / github.com/bpython/bpython / getattr_safe

Function getattr_safe

bpython/inspection.py:384–393  ·  view source on GitHub ↗

Side effect free getattr (calls getattr_static).

(obj: Any, name: str)

Source from the content-addressed store, hash-verified

382
383
384def getattr_safe(obj: Any, name: str) -> Any:
385 """Side effect free getattr (calls getattr_static)."""
386 result = inspect.getattr_static(obj, name)
387 # Slots are a MemberDescriptorType
388 if isinstance(result, MemberDescriptorType):
389 result = getattr(obj, name)
390 # classmethods are safe to access (see #966)
391 if isinstance(result, (classmethod, staticmethod)):
392 result = result.__get__(obj, obj)
393 return result
394
395
396def hasattr_safe(obj: Any, name: str) -> bool:

Callers 2

hasattr_safeFunction · 0.85
_convertFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected