Skip to content

Commit 4c5db27

Browse files
committed
Jelle's suggestion
1 parent b5baab9 commit 4c5db27

File tree

5 files changed

+18
-57
lines changed

5 files changed

+18
-57
lines changed

conformance/results/mypy/dataclasses_hash.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ Does not report when dataclass is not compatible with Hashable protocol.
66
"""
77
output = """
88
dataclasses_hash.py:14: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]
9-
dataclasses_hash.py:29: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]
10-
dataclasses_hash.py:40: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]
11-
dataclasses_hash.py:55: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]
12-
dataclasses_hash.py:69: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]
13-
dataclasses_hash.py:85: error: Expression is of type "Callable[[DC6], int]", not "None" [assert-type]
14-
dataclasses_hash.py:102: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]
9+
dataclasses_hash.py:36: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]
1510
"""
1611
conformance_automated = "Fail"
1712
errors_diff = """
1813
Line 17: Expected 1 errors
1914
Line 18: Expected 1 errors
20-
Line 43: Expected 1 errors
21-
Line 44: Expected 1 errors
15+
Line 39: Expected 1 errors
16+
Line 40: Expected 1 errors
2217
Line 14: Unexpected errors ['dataclasses_hash.py:14: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]']
23-
Line 40: Unexpected errors ['dataclasses_hash.py:40: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]']
18+
Line 36: Unexpected errors ['dataclasses_hash.py:36: error: Expression is of type "Callable[[object], int]", not "None" [assert-type]']
2419
"""

conformance/results/pyrefly/dataclasses_hash.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ errors_diff = """
55
output = """
66
ERROR dataclasses_hash.py:17:1-16: Expected a callable, got `None` [not-callable]
77
ERROR dataclasses_hash.py:18:16-22: `DC1` is not assignable to `Hashable` [bad-assignment]
8-
ERROR dataclasses_hash.py:29:12-32: assert_type((self: DC2) -> int, None) failed [assert-type]
9-
ERROR dataclasses_hash.py:43:1-16: Expected a callable, got `None` [not-callable]
10-
ERROR dataclasses_hash.py:44:16-22: `DC3` is not assignable to `Hashable` [bad-assignment]
11-
ERROR dataclasses_hash.py:55:12-32: assert_type((self: DC4) -> int, None) failed [assert-type]
12-
ERROR dataclasses_hash.py:69:12-32: assert_type((self: DC5) -> int, None) failed [assert-type]
13-
ERROR dataclasses_hash.py:85:12-32: assert_type((self: DC6) -> int, None) failed [assert-type]
14-
ERROR dataclasses_hash.py:102:12-32: assert_type((self: DC7) -> int, None) failed [assert-type]
8+
ERROR dataclasses_hash.py:39:1-16: Expected a callable, got `None` [not-callable]
9+
ERROR dataclasses_hash.py:40:16-22: `DC3` is not assignable to `Hashable` [bad-assignment]
1510
"""

conformance/results/pyright/dataclasses_hash.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ dataclasses_hash.py:18:16 - error: Type "DC1" is not assignable to declared type
55
  "DC1" is incompatible with protocol "Hashable"
66
    "__hash__" is an incompatible type
77
      Type "None" is not assignable to type "() -> int" (reportAssignmentType)
8-
dataclasses_hash.py:29:13 - error: "assert_type" mismatch: expected "None" but received "(self: DC2) -> int" (reportAssertTypeFailure)
9-
dataclasses_hash.py:43:1 - error: Object of type "None" cannot be called (reportOptionalCall)
10-
dataclasses_hash.py:44:16 - error: Type "DC3" is not assignable to declared type "Hashable"
8+
dataclasses_hash.py:39:1 - error: Object of type "None" cannot be called (reportOptionalCall)
9+
dataclasses_hash.py:40:16 - error: Type "DC3" is not assignable to declared type "Hashable"
1110
  "DC3" is incompatible with protocol "Hashable"
1211
    "__hash__" is an incompatible type
1312
      Type "None" is not assignable to type "() -> int" (reportAssignmentType)
14-
dataclasses_hash.py:55:13 - error: "assert_type" mismatch: expected "None" but received "(self: DC4) -> int" (reportAssertTypeFailure)
15-
dataclasses_hash.py:69:13 - error: "assert_type" mismatch: expected "None" but received "(self: DC5) -> int" (reportAssertTypeFailure)
16-
dataclasses_hash.py:85:13 - error: "assert_type" mismatch: expected "None" but received "(self: DC6) -> int" (reportAssertTypeFailure)
17-
dataclasses_hash.py:102:13 - error: "assert_type" mismatch: expected "None" but received "(self: DC7) -> int" (reportAssertTypeFailure)
1813
"""
1914
conformance_automated = "Pass"
2015
errors_diff = """

conformance/results/zuban/dataclasses_hash.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ Does not synthesize a `__hash__ = None` class attribute for unhashable dataclass
55
"""
66
errors_diff = """
77
Line 14: Unexpected errors ['dataclasses_hash.py:14: error: Expression is of type "Callable[[object], int]", not "None" [misc]']
8-
Line 40: Unexpected errors ['dataclasses_hash.py:40: error: Expression is of type "Callable[[object], int]", not "None" [misc]']
8+
Line 36: Unexpected errors ['dataclasses_hash.py:36: error: Expression is of type "Callable[[object], int]", not "None" [misc]']
99
"""
1010
output = """
1111
dataclasses_hash.py:14: error: Expression is of type "Callable[[object], int]", not "None" [misc]
1212
dataclasses_hash.py:17: error: "DC1" has no attribute "__hash__" [attr-defined]
1313
dataclasses_hash.py:18: error: Incompatible types in assignment (expression has type "DC1", variable has type "Hashable") [assignment]
14-
dataclasses_hash.py:29: error: Expression is of type "Callable[[object], int]", not "None" [misc]
15-
dataclasses_hash.py:40: error: Expression is of type "Callable[[object], int]", not "None" [misc]
16-
dataclasses_hash.py:43: error: "DC3" has no attribute "__hash__" [attr-defined]
17-
dataclasses_hash.py:44: error: Incompatible types in assignment (expression has type "DC3", variable has type "Hashable") [assignment]
18-
dataclasses_hash.py:55: error: Expression is of type "Callable[[object], int]", not "None" [misc]
19-
dataclasses_hash.py:69: error: Expression is of type "Callable[[object], int]", not "None" [misc]
20-
dataclasses_hash.py:85: error: Expression is of type "Callable[[DC6], int]", not "None" [misc]
21-
dataclasses_hash.py:102: error: Expression is of type "Callable[[object], int]", not "None" [misc]
14+
dataclasses_hash.py:36: error: Expression is of type "Callable[[object], int]", not "None" [misc]
15+
dataclasses_hash.py:39: error: "DC3" has no attribute "__hash__" [attr-defined]
16+
dataclasses_hash.py:40: error: Incompatible types in assignment (expression has type "DC3", variable has type "Hashable") [assignment]
2217
"""

conformance/tests/dataclasses_hash.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
from dataclasses import dataclass
6-
from typing import Hashable, assert_type
6+
from typing import Callable, Hashable, assert_type
77

88

99
@dataclass
@@ -23,11 +23,7 @@ class DC2:
2323
a: int
2424

2525

26-
# Because `DC2` is frozen, type checkers should synthesize
27-
# a callable `__hash__` method for it, and therefore should
28-
# emit a diagnostic here:
29-
assert_type(DC2.__hash__, None) # E
30-
26+
dc2_hash: Callable[..., int] = DC2.__hash__ # OK
3127
DC2(0).__hash__() # OK
3228
v2: Hashable = DC2(0) # OK
3329

@@ -49,11 +45,7 @@ class DC4:
4945
a: int
5046

5147

52-
# Because `DC4` is frozen, type checkers should synthesize
53-
# a callable `__hash__` method for it, and therefore should
54-
# emit a diagnostic here:
55-
assert_type(DC4.__hash__, None) # E
56-
48+
dc4_hash: Callable[..., int] = DC4.__hash__ # OK
5749
DC4(0).__hash__() # OK
5850
v4: Hashable = DC4(0) # OK
5951

@@ -63,11 +55,7 @@ class DC5:
6355
a: int
6456

6557

66-
# Type checkers should synthesize a callable `__hash__`
67-
# method for `DC5` due to `unsafe_hash=True`, and therefore
68-
# should emit a diagnostic here:
69-
assert_type(DC5.__hash__, None) # E
70-
58+
dc5_hash: Callable[..., int] = DC5.__hash__ # OK
7159
DC5(0).__hash__() # OK
7260
v5: Hashable = DC5(0) # OK
7361

@@ -80,10 +68,7 @@ def __hash__(self) -> int:
8068
return 0
8169

8270

83-
# Type checkers should respect the manually defined `__hash__`
84-
# method for `DC6`, and therefore should emit a diagnostic here:
85-
assert_type(DC6.__hash__, None) # E
86-
71+
dc6_hash: Callable[..., int] = DC6.__hash__ # OK
8772
DC6(0).__hash__() # OK
8873
v6: Hashable = DC6(0) # OK
8974

@@ -96,10 +81,6 @@ def __eq__(self, other) -> bool:
9681
return self.a == other.a
9782

9883

99-
# Because `DC7` is frozen, type checkers should synthesize
100-
# a callable `__hash__` method for it, and therefore should
101-
# emit a diagnostic here:
102-
assert_type(DC7.__hash__, None) # E
103-
84+
dc7_hash: Callable[..., int] = DC7.__hash__ # OK
10485
DC7(0).__hash__() # OK
10586
v7: Hashable = DC7(0) # OK

0 commit comments

Comments
 (0)