summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dataclasses.py
diff options
context:
space:
mode:
authorIurii Kemaev <6885137+hbq1@users.noreply.github.com>2021-04-06 05:14:01 (GMT)
committerGitHub <noreply@github.com>2021-04-06 05:14:01 (GMT)
commit376ffc6ac491da74920aed1b8e35bc371cb766ac (patch)
tree9b0561f3aa54ba7a825ebabc107afe5a73aec32a /Lib/test/test_dataclasses.py
parent4663e5f39e9f872dcd69545f293e832d5855d084 (diff)
downloadcpython-376ffc6ac491da74920aed1b8e35bc371cb766ac.zip
cpython-376ffc6ac491da74920aed1b8e35bc371cb766ac.tar.gz
cpython-376ffc6ac491da74920aed1b8e35bc371cb766ac.tar.bz2
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
Diffstat (limited to 'Lib/test/test_dataclasses.py')
-rw-r--r--Lib/test/test_dataclasses.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py
index 5515ca4..12c1918 100644
--- a/Lib/test/test_dataclasses.py
+++ b/Lib/test/test_dataclasses.py
@@ -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):