Skip to content

Commit

Permalink
Update Lib/test/test_capi/test_type.py
Browse files Browse the repository at this point in the history
Co-authored-by: Petr Viktorin <[email protected]>
  • Loading branch information
vstinner and encukou authored Aug 27, 2024
1 parent 0155362 commit 1c1fa7e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Lib/test/test_capi/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,32 @@ class D(A, C): pass
# all parent classes are now immutable, so D can be made immutable
# as well
type_freeze(D)


def test_freeze_meta(self):
"""test PyType_Freeze() with overridden MRO"""
type_freeze = _testcapi.type_freeze

class Base:
value = 1

class Meta(type):
def mro(cls):
return (cls, Base, object)

class FreezeThis(metaclass=Meta):
"""This has `Base` in the MRO, but not tp_bases"""

self.assertEqual(FreezeThis.value, 1)

with self.assertRaises(TypeError):
type_freeze(FreezeThis)

Base.value = 2
self.assertEqual(FreezeThis.value, 2)

type_freeze(Base)
with self.assertRaises(TypeError):
Base.value = 3
type_freeze(FreezeThis)
self.assertEqual(FreezeThis.value, 2)

0 comments on commit 1c1fa7e

Please sign in to comment.