In recent versions of Python, hasattr() only catches AttributeError. This catches all errors.
(obj: object, attr: str)
| 12 | |
| 13 | |
| 14 | def 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 | |
| 25 | def dir2(obj: object) -> list[str]: |
no outgoing calls
no test coverage detected
searching dependent graphs…