[ty] Recognize functions with stub bodies in Protocol classes as implicitly abstract#22838
[ty] Recognize functions with stub bodies in Protocol classes as implicitly abstract#22838AlexWaygood merged 7 commits intomainfrom
Protocol classes as implicitly abstract#22838Conversation
Typing conformance resultsNo changes detected ✅ |
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
empty-body |
0 | 10 | 0 |
invalid-return-type |
8 | 0 | 1 |
invalid-parameter-default |
0 | 0 | 7 |
invalid-argument-type |
1 | 2 | 3 |
invalid-assignment |
0 | 0 | 4 |
unused-type-ignore-comment |
2 | 0 | 0 |
| Total | 11 | 12 | 15 |
728fc6f to
5a0043b
Compare
charliermarsh
left a comment
There was a problem hiding this comment.
I think I personally would've expected def also_not_abstractmethod(self) -> None: ... to be considered implicitly abstract (but could understand why def also_not_abstractmethod(self) -> None: pass might not) just based on some argument around "programmer intent". Your approach is also reasonable though, that opinion is highly subjective.
5a0043b to
0baf26b
Compare
0baf26b to
718fce8
Compare
718fce8 to
86f5ce8
Compare
86f5ce8 to
ee7a9ac
Compare
0be310b to
5584031
Compare
|
Alright, I've switched the behaviour to match that of other type checkers, and made the Salsa caching more fine-grained so that we don't over-invalidate the |
These diagnostics are going away because the error code is changing from |
Co-authored-by: Carl Meyer <[email protected]>
677daaa to
24295af
Compare
Summary
Fixes astral-sh/ty#2580.
We now consider any method in a
Protocolclass to be implicitly abstract if theProtocolclass is defined in a.pyfile and of the following conditions is met regarding the method:...orpass), and they have a return type that is not assignable toNoneraise NotImplementedError, and it has a return type that is not assignable toNeverWe also now do not emit
abstract-method-in-final-classfor@finalProtocolclasses. Unlike non-Protocolclasses, it is possible to subtype aProtocolclass without explicitly subclassing it, so an@finalProtocolclass with unimplemented abstract methods is not inherently broken in the same way as an@finalnon-Protocolclass.Test Plan
mdtests and snapshots