bpo-28866: Add regression test

This commit is contained in:
Steve Palt 2019-12-11 13:23:32 +01:00 committed by Petr Viktorin
parent 0d63bacefd
commit 7b11cf037d
1 changed files with 24 additions and 0 deletions

View File

@ -5637,6 +5637,30 @@ class MroTest(unittest.TestCase):
class A(metaclass=M): class A(metaclass=M):
pass pass
def test_custom_mro_doesnt_cache(self):
"""Regression test for https://bugs.python.org/issue28866 """
class Foo:
pass
class Meta(type):
def mro(cls):
return (cls, Foo, object)
def __setattr__(cls, name, value):
setattr(Foo, name, value)
proxy = Meta('FooProxy', (), {})
proxy.x = 300
proxy.x # try to populate the cache
proxy.x = 0
# Before the fix, this retreived the old value (300) from the cache
# (That value could even be garbage-collected, if there are no other
# references to it.)
self.assertEqual(proxy.x, 0)
def test_main(): def test_main():
# Run all local test cases, with PTypesLongInitTest first. # Run all local test cases, with PTypesLongInitTest first.