diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-04-06 13:46:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-06 13:46:30 (GMT) |
commit | 8a34a0793bcb830350dac675524310bb285e5e4f (patch) | |
tree | 2fcd7aac1392b87fecbd0ffedc0e94a99df4b4f1 /Lib/test/test_dataclasses.py | |
parent | c7ccb0ff61e443633d0c54cb18b5633a8e95b30c (diff) | |
download | cpython-8a34a0793bcb830350dac675524310bb285e5e4f.zip cpython-8a34a0793bcb830350dac675524310bb285e5e4f.tar.gz cpython-8a34a0793bcb830350dac675524310bb285e5e4f.tar.bz2 |
bpo-43176: Fix processing of empty dataclasses (GH-24484) (GH-25205)
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
(cherry picked from commit 376ffc6ac491da74920aed1b8e35bc371cb766ac)
Co-authored-by: Iurii Kemaev <6885137+hbq1@users.noreply.github.com>
Co-authored-by: Iurii Kemaev <6885137+hbq1@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_dataclasses.py')
-rw-r--r-- | Lib/test/test_dataclasses.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py index 31caae9..e65db17 100644 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -2568,6 +2568,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): |