diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-05-07 17:45:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-07 17:45:09 (GMT) |
commit | 1b19bd1a88e6c410fc9cd08db48e0d35cfa8bb5a (patch) | |
tree | 3b858db3317ce265f4830ec9556988874acfdb5c /Lib/inspect.py | |
parent | 60f588478f0a3d88e86b97acecbcb569142f4636 (diff) | |
download | cpython-1b19bd1a88e6c410fc9cd08db48e0d35cfa8bb5a.zip cpython-1b19bd1a88e6c410fc9cd08db48e0d35cfa8bb5a.tar.gz cpython-1b19bd1a88e6c410fc9cd08db48e0d35cfa8bb5a.tar.bz2 |
gh-103193: cache calls to `inspect._shadowed_dict` in `inspect.getattr_static` (#104267)
Co-authored-by: Carl Meyer <carl@oddbird.net>
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 95da7fb..a64e85e 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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__. |