diff options
author | Michael Foord <michael@voidspace.org.uk> | 2011-12-22 01:15:53 (GMT) |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2011-12-22 01:15:53 (GMT) |
commit | 85530aa1c369ce83f59bb2e10b6af34c889894fb (patch) | |
tree | 146ddafe3ac4b28f0ec2cdd4d36a9aff00edcc3b /Lib | |
parent | 059226b8ec3b94255b356e770c47e4311195af91 (diff) | |
parent | 3ba95f8bd984a0033c0b2da9974f67f537dedc9e (diff) | |
download | cpython-85530aa1c369ce83f59bb2e10b6af34c889894fb.zip cpython-85530aa1c369ce83f59bb2e10b6af34c889894fb.tar.gz cpython-85530aa1c369ce83f59bb2e10b6af34c889894fb.tar.bz2 |
Merge
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/inspect.py | 9 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 17 |
2 files changed, 22 insertions, 4 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 8b800f4..fc9f612 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1186,10 +1186,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) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 17c9f40..ef0d939 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -1088,6 +1088,23 @@ class TestGetattrStatic(unittest.TestCase): self.assertIsNot(inspect.getattr_static(sys, "version", sentinel), sentinel) + def test_metaclass_with_metaclass_with_dict_as_property(self): + class MetaMeta(type): + @property + def __dict__(self): + self.executed = True + return dict(spam=42) + + class Meta(type, metaclass=MetaMeta): + executed = False + + class Thing(metaclass=Meta): + pass + + with self.assertRaises(AttributeError): + inspect.getattr_static(Thing, "spam") + self.assertFalse(Thing.executed) + class TestGetGeneratorState(unittest.TestCase): def setUp(self): |