Skip to content

Commit dca7d17

Browse files
authored
gh-103193: Speedup and inline inspect._is_type (#103321)
Improve performance of `inspect.getattr_static`
1 parent affedee commit dca7d17

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Lib/inspect.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,13 +1791,6 @@ def _check_class(klass, attr):
17911791
return entry.__dict__[attr]
17921792
return _sentinel
17931793

1794-
def _is_type(obj):
1795-
try:
1796-
_static_getmro(obj)
1797-
except TypeError:
1798-
return False
1799-
return True
1800-
18011794
def _shadowed_dict(klass):
18021795
for entry in _static_getmro(klass):
18031796
dunder_dict = _get_dunder_dict_of_class(entry)
@@ -1821,8 +1814,10 @@ def getattr_static(obj, attr, default=_sentinel):
18211814
documentation for details.
18221815
"""
18231816
instance_result = _sentinel
1824-
if not _is_type(obj):
1825-
klass = type(obj)
1817+
1818+
objtype = type(obj)
1819+
if type not in _static_getmro(objtype):
1820+
klass = objtype
18261821
dict_attr = _shadowed_dict(klass)
18271822
if (dict_attr is _sentinel or
18281823
type(dict_attr) is types.MemberDescriptorType):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy