You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test-data/unit/check-dataclasses.test
+38-2Lines changed: 38 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -260,15 +260,21 @@ class FrozenBase:
260
260
pass
261
261
262
262
@dataclass
263
-
class BadNormalDerived(FrozenBase): # E: Non-frozen dataclass cannot inherit from a frozen dataclass
263
+
class BadNormalDerived(FrozenBase): # E: Incompatible override of '__hash__': dataclasses without 'frozen' or 'unsafe_hash' have '__hash__' set to None \
264
+
# E: Non-frozen dataclass cannot inherit from a frozen dataclass
264
265
pass
265
266
266
267
@dataclass
267
268
class NormalBase:
268
269
pass
269
270
270
271
@dataclass(frozen=True)
271
-
class BadFrozenDerived(NormalBase): # E: Frozen dataclass cannot inherit from a non-frozen dataclass
272
+
class BadFrozenDerived(NormalBase): # E: Signature of "__hash__" incompatible with supertype "NormalBase" \
273
+
# N: Superclass: \
274
+
# N: None \
275
+
# N: Subclass: \
276
+
# N: def __hash__() -> int \
277
+
# E: Frozen dataclass cannot inherit from a non-frozen dataclass
272
278
pass
273
279
274
280
[builtins fixtures/dataclasses.pyi]
@@ -2636,3 +2642,33 @@ Good(4)
2636
2642
AlsoGood(4)
2637
2643
Bad(4)
2638
2644
[builtins fixtures/tuple.pyi]
2645
+
2646
+
[case testDataclassHash2]
2647
+
import dataclasses
2648
+
2649
+
# This
2650
+
@dataclasses.dataclass()
2651
+
class Parent:
2652
+
a: int
2653
+
2654
+
# is (at runtime, ignoring other methods) the same as
2655
+
class ExplicitParent:
2656
+
a: int
2657
+
__hash__ = None
2658
+
2659
+
class Child(Parent):
2660
+
def __hash__(self) -> int: # E: Signature of "__hash__" incompatible with supertype "Parent" \
2661
+
# N: Superclass: \
2662
+
# N: None \
2663
+
# N: Subclass: \
2664
+
# N: def __hash__(self) -> int
2665
+
return 0
2666
+
2667
+
class ExplicitChild(ExplicitParent):
2668
+
def __hash__(self) -> int: # E: Signature of "__hash__" incompatible with supertype "ExplicitParent" \
0 commit comments