Side effect free getattr (calls getattr_static).
(obj: Any, name: str)
| 382 | |
| 383 | |
| 384 | def 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 | |
| 396 | def hasattr_safe(obj: Any, name: str) -> bool: |
no outgoing calls
no test coverage detected