gh-103193: cache calls to inspect._shadowed_dict in inspect.getattr_static (#104267)

Co-authored-by: Carl Meyer <carl@oddbird.net>
This commit is contained in:
Alex Waygood 2023-05-07 18:45:09 +01:00 committed by GitHub
parent 60f588478f
commit 1b19bd1a88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 5 deletions

View file

@ -2111,6 +2111,28 @@ class TestGetattrStatic(unittest.TestCase):
self.assertEqual(inspect.getattr_static(foo, 'a'), 3)
self.assertFalse(test.called)
def test_mutated_mro(self):
test = self
test.called = False
class Foo(dict):
a = 3
@property
def __dict__(self):
test.called = True
return {}
class Bar(dict):
a = 4
class Baz(Bar): pass
baz = Baz()
self.assertEqual(inspect.getattr_static(baz, 'a'), 4)
Baz.__bases__ = (Foo,)
self.assertEqual(inspect.getattr_static(baz, 'a'), 3)
self.assertFalse(test.called)
def test_custom_object_dict(self):
test = self
test.called = False