Commit 8f9cc877 authored by Inada Naoki's avatar Inada Naoki Committed by GitHub

bpo-38026: fix inspect.getattr_static (GH-15676)

It should avoid dynamic lookup including `isinstance`.

This is a regression caused by GH-5351.
parent 2cd90258
...@@ -1558,7 +1558,7 @@ def _shadowed_dict(klass): ...@@ -1558,7 +1558,7 @@ def _shadowed_dict(klass):
except KeyError: except KeyError:
pass pass
else: else:
if not (isinstance(class_dict, types.GetSetDescriptorType) and if not (type(class_dict) is types.GetSetDescriptorType and
class_dict.__name__ == "__dict__" and class_dict.__name__ == "__dict__" and
class_dict.__objclass__ is entry): class_dict.__objclass__ is entry):
return class_dict return class_dict
...@@ -1580,7 +1580,7 @@ def getattr_static(obj, attr, default=_sentinel): ...@@ -1580,7 +1580,7 @@ def getattr_static(obj, attr, default=_sentinel):
klass = type(obj) klass = type(obj)
dict_attr = _shadowed_dict(klass) dict_attr = _shadowed_dict(klass)
if (dict_attr is _sentinel or if (dict_attr is _sentinel or
isinstance(dict_attr, types.MemberDescriptorType)): type(dict_attr) is types.MemberDescriptorType):
instance_result = _check_instance(obj, attr) instance_result = _check_instance(obj, attr)
else: else:
klass = obj klass = obj
......
Fixed :func:`inspect.getattr_static` used ``isinstance`` while it should
avoid dynamic lookup.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment