Skip to content

Commit

Permalink
pythongh-103193: Speedup and inline inspect._is_type
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Apr 6, 2023
1 parent affedee commit 1bacc91
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,13 +1791,6 @@ def _check_class(klass, attr):
return entry.__dict__[attr]
return _sentinel

def _is_type(obj):
try:
_static_getmro(obj)
except TypeError:
return False
return True

def _shadowed_dict(klass):
for entry in _static_getmro(klass):
dunder_dict = _get_dunder_dict_of_class(entry)
Expand All @@ -1821,8 +1814,10 @@ def getattr_static(obj, attr, default=_sentinel):
documentation for details.
"""
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)
if (dict_attr is _sentinel or
type(dict_attr) is types.MemberDescriptorType):
Expand Down

0 comments on commit 1bacc91

Please sign in to comment.