Metaclasses with metaclasses with a __dict__ descriptor can no longer trigger code execution with inspect.getattr_static.

Closes issue 11829.
This commit is contained in:
Michael Foord 2011-12-22 01:13:37 +00:00
parent 65a3f4b8c5
commit 3ba95f8bd9
3 changed files with 25 additions and 4 deletions

View file

@ -1161,10 +1161,11 @@ def getattr_static(obj, attr, default=_sentinel):
if obj is klass:
# for types we check the metaclass too
for entry in _static_getmro(type(klass)):
try:
return entry.__dict__[attr]
except KeyError:
pass
if _shadowed_dict(type(entry)) is _sentinel:
try:
return entry.__dict__[attr]
except KeyError:
pass
if default is not _sentinel:
return default
raise AttributeError(attr)