[ty] Emit a diagnostic for subclassing with order=True#21704
Conversation
order=Trueorder=True
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134. |
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. |
|
| Project | Old Time | New Time | Change |
|---|---|---|---|
pandas-stubs |
8.57s | 13.19s | +54% |
|
@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 reportSummary
Significant changesClick to expand detailed breakdownsphinx
prefect
trio
flake8
|
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.
a727348 to
b2b1ccd
Compare
de0114e to
b12fda2
Compare
|
Charlie, sorry for the delay here. This is still low prio, and more complicated than it looks. Working on it... |
|
My current problem is that I think inheriting from >>> @dataclass(order=True)
... class C:
... x: int
...
>>> @dataclass(order=True)
... class D(C):
... y: str
...
>>> C(1) < D(2, "a")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'C' and 'D'That means you can't safely use a |
|
I'm fine to just close this and prioritize other work if you prefer, not a big deal and clearly more complicated than initially perceived. |
Even cases where you don't add new fields in the child class are unsafe, I believe -- see the example in the original issue I wrote up!
Not sure I follow... you just think it would be so many diagnostics that it would be overwhelming for users? Maybe, but I'm not sure |
As you can see from the ecosystem report, some dataclass-transformer libraries set But I guess we could make that rule opt-in? |
|
Ah I see. Sorry, I hadn't looked at the ecosystem report, and didn't consider the impact on third-party dataclass-transformer libraries. Are we not able to distinguish between stdlib dataclasses and third-party libraries? Could we add that distinction? I'd be fine making this rule only apply to stdlib dataclasses. We may need to add this distinction anyway, to fix issues like astral-sh/ty#3486, where third-party dataclass-transform libraries behave differently to stdlib dataclasses. |
It's easy to distinguish between the two. In fact, the original version here only implemented the check for stdlib dataclasses, but I argued that we should treat dataclass transformers in the same way ("If dataclass_transform is applied to a class, dataclass-like semantics will be assumed [...]") 🙃 I'll leave it up to you to decide what we do here (I will make the changes accordingly):
|
I'm cool with this, though also cool with just closing for now and calling this a non-priority for stable. |
|
I'd also go with
I think unfortunately it's pretty clear that third-party
...I'm less sure that we want to abide by that principle so strictly when it comes to things like "in this specific edge case, the stdlib dataclasses module is known to raise a |
sharkdp
left a comment
There was a problem hiding this comment.
Ok, this is happening!
(very sorry this took so long)
…1704) ## Summary Closes astral-sh/ty#1681. --------- Co-authored-by: David Peter <[email protected]>
…1704) ## Summary Closes astral-sh/ty#1681. --------- Co-authored-by: David Peter <[email protected]>
Summary
Closes astral-sh/ty#1681.