diff options
-rw-r--r-- | Lib/inspect.py | 9 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 6 |
2 files changed, 13 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 2f05829..241cd08 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1080,6 +1080,13 @@ def _check_class(klass, attr): pass return _sentinel +def _is_type(obj): + try: + _static_getmro(obj) + except TypeError: + return False + return True + def getattr_static(obj, attr, default=_sentinel): """Retrieve attributes without triggering dynamic lookup via the @@ -1093,7 +1100,7 @@ def getattr_static(obj, attr, default=_sentinel): documentation for details. """ instance_result = _sentinel - if not isinstance(obj, type): + if not _is_type(obj): instance_result = _check_instance(obj, attr) klass = type(obj) else: diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index b3e131c..df480b8 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -860,11 +860,15 @@ class TestGetattrStatic(unittest.TestCase): foo = 3 class Something(Base): + executed = False @property def __class__(self): + self.executed = True return object - self.assertEqual(inspect.getattr_static(Something(), 'foo'), 3) + instance = Something() + self.assertEqual(inspect.getattr_static(instance, 'foo'), 3) + self.assertFalse(instance.executed) self.assertEqual(inspect.getattr_static(Something, 'foo'), 3) def test_mro_as_property(self): |