Skip to content

Commit 2a31576

Browse files
committed
Add additional test regarding custom __lt__ method
1 parent cc3ba13 commit 2a31576

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

crates/red_knot_python_semantic/resources/mdtest/dataclasses.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ GenericWithOrder[int](1) < GenericWithOrder[int](1)
173173
GenericWithOrder[int](1) < GenericWithOrder[str]("a") # error: [unsupported-operator]
174174
```
175175

176+
If a class already defines one of the comparison methods, a `TypeError` is raised at runtime.
177+
Ideally, we would emit a diagnostic in that case:
178+
179+
```py
180+
@dataclass(order=True)
181+
class AlreadyHasCustomDunderLt:
182+
x: int
183+
184+
# TODO: Ideally, we would emit a diagnostic here
185+
def __lt__(self, other: object) -> bool:
186+
return False
187+
```
188+
176189
### `unsafe_hash`
177190

178191
To do

0 commit comments

Comments
 (0)