mirror of https://github.com/python/cpython
gh-103193: Speedup and inline `inspect._is_type` (#103321)
Improve performance of `inspect.getattr_static`
This commit is contained in:
parent
affedee8bf
commit
dca7d174f1
|
@ -1791,13 +1791,6 @@ def _check_class(klass, attr):
|
||||||
return entry.__dict__[attr]
|
return entry.__dict__[attr]
|
||||||
return _sentinel
|
return _sentinel
|
||||||
|
|
||||||
def _is_type(obj):
|
|
||||||
try:
|
|
||||||
_static_getmro(obj)
|
|
||||||
except TypeError:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _shadowed_dict(klass):
|
def _shadowed_dict(klass):
|
||||||
for entry in _static_getmro(klass):
|
for entry in _static_getmro(klass):
|
||||||
dunder_dict = _get_dunder_dict_of_class(entry)
|
dunder_dict = _get_dunder_dict_of_class(entry)
|
||||||
|
@ -1821,8 +1814,10 @@ def getattr_static(obj, attr, default=_sentinel):
|
||||||
documentation for details.
|
documentation for details.
|
||||||
"""
|
"""
|
||||||
instance_result = _sentinel
|
instance_result = _sentinel
|
||||||
if not _is_type(obj):
|
|
||||||
klass = type(obj)
|
objtype = type(obj)
|
||||||
|
if type not in _static_getmro(objtype):
|
||||||
|
klass = objtype
|
||||||
dict_attr = _shadowed_dict(klass)
|
dict_attr = _shadowed_dict(klass)
|
||||||
if (dict_attr is _sentinel or
|
if (dict_attr is _sentinel or
|
||||||
type(dict_attr) is types.MemberDescriptorType):
|
type(dict_attr) is types.MemberDescriptorType):
|
||||||
|
|
Loading…
Reference in New Issue