Skip to content

Commit bdcbb83

Browse files
bpo-38026: fix inspect.getattr_static (GH-15676)
It should avoid dynamic lookup including `isinstance`. This is a regression caused by GH-5351. (cherry picked from commit 8f9cc87) Co-authored-by: Inada Naoki <[email protected]>
1 parent 9c2654d commit bdcbb83

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Lib/inspect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ def _shadowed_dict(klass):
15581558
except KeyError:
15591559
pass
15601560
else:
1561-
if not (isinstance(class_dict, types.GetSetDescriptorType) and
1561+
if not (type(class_dict) is types.GetSetDescriptorType and
15621562
class_dict.__name__ == "__dict__" and
15631563
class_dict.__objclass__ is entry):
15641564
return class_dict
@@ -1580,7 +1580,7 @@ def getattr_static(obj, attr, default=_sentinel):
15801580
klass = type(obj)
15811581
dict_attr = _shadowed_dict(klass)
15821582
if (dict_attr is _sentinel or
1583-
isinstance(dict_attr, types.MemberDescriptorType)):
1583+
type(dict_attr) is types.MemberDescriptorType):
15841584
instance_result = _check_instance(obj, attr)
15851585
else:
15861586
klass = obj
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed :func:`inspect.getattr_static` used ``isinstance`` while it should
2+
avoid dynamic lookup.

0 commit comments

Comments
 (0)