MCPcopy Create free account
hub / github.com/ipython/ipython / safe_hasattr

Function safe_hasattr

IPython/utils/dir2.py:12–20  ·  view source on GitHub ↗

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

(obj, attr)

Source from the content-addressed store, hash-verified

10
11
12def safe_hasattr(obj, attr):
13 """In recent versions of Python, hasattr() only catches AttributeError.
14 This catches all errors.
15 """
16 try:
17 getattr(obj, attr)
18 return True
19 except:
20 return False
21
22
23def dir2(obj):

Callers 4

getargspecFunction · 0.90
_get_wrappedFunction · 0.90
_infoMethod · 0.90
dir2Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected