mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-103193: cache calls to inspect._shadowed_dict
in inspect.getattr_static
(#104267)
Co-authored-by: Carl Meyer <carl@oddbird.net>
This commit is contained in:
parent
60f588478f
commit
1b19bd1a88
3 changed files with 32 additions and 5 deletions
|
@ -1794,8 +1794,9 @@ def _check_class(klass, attr):
|
|||
return entry.__dict__[attr]
|
||||
return _sentinel
|
||||
|
||||
def _shadowed_dict(klass):
|
||||
for entry in _static_getmro(klass):
|
||||
@functools.lru_cache()
|
||||
def _shadowed_dict_from_mro_tuple(mro):
|
||||
for entry in mro:
|
||||
dunder_dict = _get_dunder_dict_of_class(entry)
|
||||
if '__dict__' in dunder_dict:
|
||||
class_dict = dunder_dict['__dict__']
|
||||
|
@ -1805,6 +1806,9 @@ def _shadowed_dict(klass):
|
|||
return class_dict
|
||||
return _sentinel
|
||||
|
||||
def _shadowed_dict(klass):
|
||||
return _shadowed_dict_from_mro_tuple(_static_getmro(klass))
|
||||
|
||||
def getattr_static(obj, attr, default=_sentinel):
|
||||
"""Retrieve attributes without triggering dynamic lookup via the
|
||||
descriptor protocol, __getattr__ or __getattribute__.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue