diff -r 82557279efd2 Lib/inspect.py --- a/Lib/inspect.py Wed Dec 21 16:52:40 2011 +0100 +++ b/Lib/inspect.py Wed Dec 21 22:27:19 2011 +0100 @@ -1161,10 +1161,11 @@ 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 -r 82557279efd2 Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Wed Dec 21 16:52:40 2011 +0100 +++ b/Lib/test/test_inspect.py Wed Dec 21 22:27:19 2011 +0100 @@ -1088,6 +1088,23 @@ 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):