mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
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:
parent
60f588478f
commit
1b19bd1a88
3 changed files with 32 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue