[ty] Fix subtyping/assignability for @property protocol members#23034
[ty] Fix subtyping/assignability for @property protocol members#23034charliermarsh wants to merge 3 commits intomainfrom
@property protocol members#23034Conversation
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 82.27% to 82.52%. The percentage of expected errors that received a diagnostic increased from 72.99% to 73.82%. Summary
True positives addedDetails
False positives removedDetails
|
|
CodSpeed Performance ReportMerging this PR will degrade performance by 8.31%Comparing Summary
Performance Changes
Footnotes
|
4b88a0c to
4a0fe00
Compare
|
Thanks for picking this up!! FWIW I'd expect a regression here, because we're doing a fair bit more work than we were before (though obviously we should try to keep it to a minimum). IIRC, the remaining things I had on my todo list for this PR were:
|
|
Very helpful, thank you! I was trying to limit the changes and omit (e.g.) the cosmetic diagnostic changes from the other PR. I'll see if I can pull those out into separate PRs too. |
|
I believe the rich diagnostics are true positives -- like: from typing import Protocol, NamedTuple
class EdgeProtocol(Protocol):
size: int # Mutable attribute member - can be read AND written
class EdgeNamedTuple(NamedTuple):
size: int # Immutable field - can only be read, NOT written
def process(edge: EdgeProtocol) -> None:
edge.size = 10 # Protocol allows this - it's a mutable attribute
nt = EdgeNamedTuple(size=5)
process(nt) # Error! NamedTuple fields are immutable
nt.size = 10 # This would fail at runtime: AttributeErrorPyright also flags an error. |
4a0fe00 to
4f006e6
Compare
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
type-assertion-failure |
73 | 573 | 195 |
unsupported-operator |
283 | 0 | 1 |
no-matching-overload |
186 | 21 | 0 |
invalid-argument-type |
30 | 3 | 15 |
unresolved-attribute |
1 | 30 | 1 |
invalid-assignment |
0 | 16 | 3 |
invalid-return-type |
9 | 8 | 2 |
unused-type-ignore-comment |
1 | 6 | 0 |
possibly-missing-attribute |
4 | 0 | 2 |
not-subscriptable |
5 | 0 | 0 |
invalid-method-override |
2 | 0 | 0 |
not-iterable |
0 | 1 | 0 |
| Total | 594 | 658 | 219 |
|
I'm going to hesitantly mark ready for review. My goal here was largely to rebase Alex's work, then iterate on the ecosystem reports to fix any false positives. The ecosystem report largely looks good (at least, I fixed several false positives), though there's clearly a lot of churn in ordering, etc., that's making it a bit hard to wade through. |
Also properly support @classmethod and @staticmethod protocol members instead of using todo_type!() placeholders. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4f006e6 to
8c30db9
Compare
|
@AlexWaygood I'm tentatively assigning this to you for review? Let me know if you don't want to be the assigned reviewer. |
Summary
Attempting to revive #19936.