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

Function safe_hasattr

IPython/utils/dir2.py:14–22  ·  view source on GitHub ↗

In recent versions of Python, hasattr() only catches AttributeError. This catches all errors.

(obj: object, attr: str)

Source from the content-addressed store, hash-verified

12
13
14def safe_hasattr(obj: object, attr: str) -> bool:
15 """In recent versions of Python, hasattr() only catches AttributeError.
16 This catches all errors.
17 """
18 try:
19 getattr(obj, attr)
20 return True
21 except:
22 return False
23
24
25def dir2(obj: object) -> list[str]:

Callers 3

_get_wrappedFunction · 0.90
infoMethod · 0.90
dir2Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…