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
# 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)]
)