Skip to content

Commit 1ed3f69

Browse files
committed
Update another affected test, add explicit example of None -> method override.
1 parent 7d70459 commit 1ed3f69

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

test-data/unit/check-dataclasses.test

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,21 @@ class FrozenBase:
260260
pass
261261

262262
@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
264265
pass
265266

266267
@dataclass
267268
class NormalBase:
268269
pass
269270

270271
@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
272278
pass
273279

274280
[builtins fixtures/dataclasses.pyi]
@@ -2636,3 +2642,33 @@ Good(4)
26362642
AlsoGood(4)
26372643
Bad(4)
26382644
[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" \
2669+
# N: Superclass: \
2670+
# N: None \
2671+
# N: Subclass: \
2672+
# N: def __hash__(self) -> int
2673+
return 0
2674+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)