[ty] Emit a diagnostic for subclassing with order=True#21704
[ty] Emit a diagnostic for subclassing with order=True#21704charliermarsh wants to merge 2 commits intomainfrom
order=True#21704Conversation
order=Trueorder=True
Typing conformance resultsNo changes detected ✅ |
|
bc1c309 to
4e4b08c
Compare
|
I believe those changes on the conformance tests are "correct" in-so-far as those are instances of the case we want to catch here. |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
40 | 0 | 0 |
subclass-of-dataclass-with-order |
5 | 0 | 0 |
invalid-return-type |
1 | 0 | 0 |
| Total | 46 | 0 | 0 |
crates/ty_python_semantic/resources/mdtest/dataclasses/dataclasses.md
Outdated
Show resolved
Hide resolved
|
@charliermarsh are you still interested in getting this over the line? |
|
Yes sir, sorry, lost track. |
24d480b to
634765c
Compare
|
I think the Expression diagnostic is correct: |
634765c to
521e4b4
Compare
Memory usage reportMemory usage unchanged ✅ |
ef4cee5 to
151ce7e
Compare
| &class_node.bases()[i], | ||
| base_params, | ||
| ); | ||
| if let Some(class_params) = class.dataclass_params(self.db()) { |
There was a problem hiding this comment.
This will only for work standard library dataclasses. I haven't looked closer at this PR, but we should probably make sure that this works for dataclass_transformers as well. See #23366 for a related PR that expands the frozen/non-frozen-inheritance checks here in the same way.
There was a problem hiding this comment.
Thanks, I attempted to fix it...
There was a problem hiding this comment.
Thank you. I will get this PR merged once #23366 lands.
151ce7e to
a727348
Compare
a727348 to
b2b1ccd
Compare
b2b1ccd to
25b032f
Compare
sharkdp
left a comment
There was a problem hiding this comment.
I wanted to get this merged today, but I think it's not quite there yet, so I'm moving this back to draft for now. I'll finish this once I get back.
It doesn't seem to be of high priority. No other type checker supports this, and it's not tested in the conformance suite.
| If the child class also has `order=True`, the diagnostic is suppressed because the child overrides | ||
| all comparison methods: | ||
|
|
||
| ```py | ||
| @dataclass(order=True) | ||
| class OrderedParent2: | ||
| x: int | ||
|
|
||
| @dataclass(order=True) | ||
| class OrderedChild2(OrderedParent2): | ||
| y: str | ||
| ``` |
There was a problem hiding this comment.
But OrderedChild2(1,2) < OrderedParent2(1) also fails at runtime. I'm not sure I understand why we suppress the diagnostic in this case?
Summary
Closes astral-sh/ty#1681.