[red-knot] Support calling a typing.Callable#16888
Merged
dhruvmanila merged 1 commit intomainfrom Mar 22, 2025
Merged
Conversation
19 tasks
Contributor
|
ce99af3 to
f29d27a
Compare
Member
Author
|
The ecosystem checks looks good except for two things:
def test(key: Optional[Callable[[str], Any]] = None) -> None:
if key is not None:
reveal_type(key) # revealed: ((str, /) -> Any) | ~None
def key_callback(text: str) -> Any:
reveal_type(key) # revealed: ((str, /) -> Any) | None
# red-knot: Object of type `None` is not callable [lint:call-non-callable]
return key(text) |
AlexWaygood
approved these changes
Mar 21, 2025
AlexWaygood
reviewed
Mar 21, 2025
Comment on lines
+20
to
+24
| def _(c: Callable[[int, str], None]): | ||
| # error: [unknown-argument] "Argument `a` does not match any known parameter" | ||
| # error: [unknown-argument] "Argument `b` does not match any known parameter" | ||
| # error: [missing-argument] "No arguments provided for required parameters 1, 2" | ||
| reveal_type(c(a=1, b="b")) # revealed: None |
Member
There was a problem hiding this comment.
there's room for the error message to be improved here, but it's out of scope for this PR:
Suggested change
| def _(c: Callable[[int, str], None]): | |
| # error: [unknown-argument] "Argument `a` does not match any known parameter" | |
| # error: [unknown-argument] "Argument `b` does not match any known parameter" | |
| # error: [missing-argument] "No arguments provided for required parameters 1, 2" | |
| reveal_type(c(a=1, b="b")) # revealed: None | |
| def _(c: Callable[[int, str], None]): | |
| # error: [unknown-argument] "Keyword argument `a` does not match any known parameter (`c` accepts no keyword arguments)" | |
| # error: [unknown-argument] "Keyword argument `b` does not match any known parameter (`c` accepts no keyword arguments)" | |
| # error: [missing-argument] "No arguments provided for required parameters 1, 2" | |
| reveal_type(c(a=1, b="b")) # revealed: None |
Member
Author
There was a problem hiding this comment.
#16919, feel free to update the description or comment to provide more context and examples.
carljm
approved these changes
Mar 21, 2025
Contributor
carljm
left a comment
There was a problem hiding this comment.
Awesome! Tests were most of the work here, it looks like :)
f29d27a to
079810b
Compare
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
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
Part of #15382, this PR adds support for calling a variable that's annotated with
typing.Callable.Test Plan
Add test cases in a new
call/annotation.mdfile.