Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,9 +1706,13 @@ def _check_instance(obj, attr):


def _check_class(klass, attr):
last_meta = None
for entry in _static_getmro(klass):
if _shadowed_dict(type(entry)) is _sentinel and attr in entry.__dict__:
return entry.__dict__[attr]
meta = type(entry)
if meta is last_meta or _shadowed_dict(meta) is _sentinel:
last_meta = meta
if attr in entry.__dict__:
return entry.__dict__[attr]
return _sentinel


Expand Down Expand Up @@ -1740,6 +1744,9 @@ def _shadowed_dict(klass):
# destroyed, and the dynamically created classes happen to be the only
# objects that hold strong references to other objects that take up a
# significant amount of memory.
# Fast path: `type` is the dominant caller; result is always _sentinel.
if klass is type:
return _sentinel
return _shadowed_dict_from_weakref_mro_tuple(
*[make_weakref(entry) for entry in _static_getmro(klass)]
)
Expand Down
Loading