Skip to content

Commit dbd9fcf

Browse files
committed
inspect: cache last metaclass in _check_class MRO loop
Consecutive MRO entries usually share their metaclass, so call _shadowed_dict at most once per distinct metaclass.
1 parent e3cf5fa commit dbd9fcf

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/inspect.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,9 +1706,13 @@ def _check_instance(obj, attr):
17061706

17071707

17081708
def _check_class(klass, attr):
1709+
last_meta = None
17091710
for entry in _static_getmro(klass):
1710-
if _shadowed_dict(type(entry)) is _sentinel and attr in entry.__dict__:
1711-
return entry.__dict__[attr]
1711+
meta = type(entry)
1712+
if meta is last_meta or _shadowed_dict(meta) is _sentinel:
1713+
last_meta = meta
1714+
if attr in entry.__dict__:
1715+
return entry.__dict__[attr]
17121716
return _sentinel
17131717

17141718

0 commit comments

Comments
 (0)