summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/dataclasses.py2
-rwxr-xr-xLib/test/test_dataclasses.py24
2 files changed, 25 insertions, 1 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index c38e16a..5825e8e 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -834,7 +834,7 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
# Only process classes that have been processed by our
# decorator. That is, they have a _FIELDS attribute.
base_fields = getattr(b, _FIELDS, None)
- if base_fields:
+ if base_fields is not None:
has_dataclass_bases = True
for f in base_fields.values():
fields[f.name] = f
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py
index bbcf30c..548f10b 100755
--- 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):