-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[red-knot] Special case @abstractmethod for function type
#17591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dcreager
approved these changes
Apr 23, 2025
dhruvmanila
commented
Apr 23, 2025
AlexWaygood
approved these changes
Apr 23, 2025
Contributor
|
6f23ff0 to
991fe50
Compare
Member
Author
|
(Updated to use match arms instead of if blocks for |
This is required because otherwise the inferred type is not going to be
`Type::FunctionLiteral` but a todo type because we don't recognize
`TypeVar` yet:
```py
_FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
def abstractmethod(funcobj: _FuncT) -> _FuncT: ...
```
Member
Author
|
The ecosystem changes are mainly because we now type check the method that exists in the subclass of an abstract base class and in their stubs the methods are marked as |
991fe50 to
998096e
Compare
carljm
approved these changes
Apr 23, 2025
Member
Author
dcreager
added a commit
that referenced
this pull request
Apr 24, 2025
* main: [red-knot] fix collapsing literal and its negation to object (#17605) [red-knot] Add more tests for protocols (#17603) [red-knot] Ban direct instantiations of `Protocol` classes (#17597) [`pyupgrade`] Preserve parenthesis when fixing native literals containing newlines (`UP018`) (#17220) [`airflow`] fix typos (`AIR302`, `AIR312`) (#17574) [red-knot] Special case `@abstractmethod` for function type (#17591) [red-knot] Emit diagnostics for isinstance() and issubclass() calls where a non-runtime-checkable protocol is the second argument (#17561) [red-knot] Infer the members of a protocol class (#17556) [red-knot] Add `FunctionType::to_overloaded` (#17585) [red-knot] Add mdtests for `global` statement (#17563) [syntax-errors] Make duplicate parameter names a semantic error (#17131)
dhruvmanila
added a commit
that referenced
this pull request
Apr 24, 2025
## Summary This PR adds special-casing for `@final` and `@override` decorator for a similar reason as #17591 to support the invalid overload check. Both `final` and `override` are identity functions which can be removed once `TypeVar` support is added.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This is required because otherwise the inferred type is not going to be
Type::FunctionLiteralbut a todo type because we don't recognizeTypeVaryet:This is mainly required to raise diagnostic when only some (and not all)
@overload-ed functions are decorated with@abstractmethod.