On this page
inspect.getattr_static
Prev: inspect.getasyncgenstate | Up: inspect | Next: inspect.getblock
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.getattr_static
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import getattr_static
Signature & Overview
inspect.getattr_static(obj, attr, default=<object object at 0x1040b4700>)
Retrieve attributes without triggering dynamic lookup via the descriptor protocol, getattr or getattribute.
Usage
import inspect
class Boom:
@property
def val(self):
raise RuntimeError("side effect!")
# Retrieves the property object itself without invoking Boom.val.fget
prop = inspect.getattr_static(Boom(), "val")
assert isinstance(prop, property)
Gotchas
- Safe inspection without running descriptors or
__getattr__: Essential in debuggers, IDEs, and test frameworks so inspecting an object never triggers expensive properties.
REPL Inspect
from inspect import getattr_static
help(getattr_static)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/getasyncgenstate Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/getblock Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/inspect/ArgInfo Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Arguments Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Attribute Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BlockFinder Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BoundArguments shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BufferFlags shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/ClassFoundException shared tags: #inspect, #stdlib