mirror of
https://github.com/python/cpython.git
synced 2025-07-12 22:05:16 +00:00
bpo-43176: Fix processing of empty dataclasses (GH-24484)
When a dataclass inherits from an empty base, all immutability checks are omitted. This PR fixes this and adds tests for it. Automerge-Triggered-By: GH:ericvsmith
This commit is contained in:
parent
4663e5f39e
commit
376ffc6ac4
3 changed files with 26 additions and 1 deletions
|
@ -2594,6 +2594,30 @@ class TestFrozen(unittest.TestCase):
|
|||
self.assertEqual(d.i, 0)
|
||||
self.assertEqual(d.j, 10)
|
||||
|
||||
def test_inherit_nonfrozen_from_empty_frozen(self):
|
||||
@dataclass(frozen=True)
|
||||
class C:
|
||||
pass
|
||||
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'cannot inherit non-frozen dataclass from a frozen one'):
|
||||
@dataclass
|
||||
class D(C):
|
||||
j: int
|
||||
|
||||
def test_inherit_nonfrozen_from_empty(self):
|
||||
@dataclass
|
||||
class C:
|
||||
pass
|
||||
|
||||
@dataclass
|
||||
class D(C):
|
||||
j: int
|
||||
|
||||
d = D(3)
|
||||
self.assertEqual(d.j, 3)
|
||||
self.assertIsInstance(d, C)
|
||||
|
||||
# Test both ways: with an intermediate normal (non-dataclass)
|
||||
# class and without an intermediate class.
|
||||
def test_inherit_nonfrozen_from_frozen(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue