-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[red-knot] Handle unions of callables better #16716
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
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
4e5994c
Rename bindings types
dcreager 90e4b9b
Move Bindings into bind module
dcreager adede59
Make bind_call/overload constructor methods
dcreager 57b400c
Add dunder_call to callable signature
dcreager e611d6f
Mostly working
dcreager c3a3659
There we go
dcreager 453dbfa
Remove unused stuff
dcreager 61a1cea
clippy
dcreager 1266d0f
lint
dcreager 0bf32e3
Clean up error types more
dcreager 06825f2
Merge branch 'main' into dcreager/union-callables
dcreager a85b6d5
Fix merge conflicts
dcreager 88ad36f
clippy
dcreager 903bfde
Track call signatures
dcreager 71fe9ff
Back to `try_call`
dcreager a1596da
Better comment for `Type::signatures`
dcreager da5eef3
Remove all mut use of Signatures
dcreager fb9fd6e
Track signatures structs
dcreager d0a07fc
Simplify signatures a bit
dcreager 9d525c7
Store signature in callable binding too
dcreager b6af683
Change to iter/iter_mut
dcreager 834d4aa
fix doc links
dcreager 675e496
lint
dcreager 19a1e53
Untrack signatures
dcreager b2b943c
Back to mut
dcreager fd3d579
Remove (some) stutter from call errors
dcreager d279145
Apply suggestions from code review
dcreager dda63db
Fewer is_known calls
dcreager d997944
Only iterate errors if there are any
dcreager b4103ab
CallableDescriptor → Description
dcreager 9cf9e28
Doesn't panic anymore
dcreager 00891ae
ty → type
dcreager aa2d77c
Merge branch 'main' into dcreager/union-callables
dcreager 3357df6
Apply suggestions from code review
dcreager 9957879
Panic again
dcreager aed2a87
Remove unneeded lifetime params
dcreager e770680
Comment empty overloads vec
dcreager 0cf9acd
Better comments
dcreager 1cd9df8
Use bool for dunder_call_is_possibly_unbound
dcreager 11951dd
callable_descriptor → description
dcreager 86be76a
Clarify CallError comments
dcreager 6d00d40
Bring back replace_type
dcreager 9082b4b
Don't intern signatures
dcreager edc8c1d
Add with_bound_type
dcreager bb17715
clippy
dcreager 50f4bd3
Match on the binding type
dcreager 3946f37
replace iter methods with IntoIterator impls
dcreager 9677ec5
reduce indentation
dcreager f7b8247
Clarify boxed bindings in `CallError`
dcreager 608ad34
clippy
dcreager 2e317e1
Use SmallVec to optimize non-union and non-overloads
dcreager 1d5c021
Remove into_result for real I guess
dcreager 23c311d
clippy
dcreager c794612
Remove some identation
dcreager c9499b7
Merge branch 'main' into dcreager/union-callables
dcreager fd1ccd8
todo half done
dcreager 28c2c62
Remove multiple class is_known calls
dcreager e57f986
Fix test assertions
dcreager 7c88a34
Update crates/red_knot_python_semantic/src/types.rs
dcreager 6dc3dcf
Update tests
dcreager e460c80
Merge branch 'main' into dcreager/union-callables
dcreager File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,7 +121,7 @@ if NotBoolable(): | |
|
|
||
| ```py | ||
| class NotBoolable: | ||
| __bool__ = None | ||
| __bool__: None = None | ||
|
|
||
| # error: [unsupported-bool-conversion] "Boolean conversion is unsupported for type `NotBoolable`; its `__bool__` method isn't callable" | ||
| if NotBoolable(): | ||
|
|
@@ -133,9 +133,9 @@ if NotBoolable(): | |
| ```py | ||
| def test(cond: bool): | ||
| class NotBoolable: | ||
| __bool__ = None if cond else 3 | ||
| __bool__: int | None = None if cond else 3 | ||
|
|
||
| # error: [unsupported-bool-conversion] "Boolean conversion is unsupported for type `NotBoolable`; it incorrectly implements `__bool__`" | ||
| # error: [unsupported-bool-conversion] "Boolean conversion is unsupported for type `NotBoolable`; its `__bool__` method isn't callable" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here |
||
| if NotBoolable(): | ||
| ... | ||
| ``` | ||
|
|
@@ -145,7 +145,7 @@ def test(cond: bool): | |
| ```py | ||
| def test(cond: bool): | ||
| class NotBoolable: | ||
| __bool__ = None | ||
| __bool__: None = None | ||
|
|
||
| a = 10 if cond else NotBoolable() | ||
|
|
||
|
|
||
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without these changes, we infer the type of
__bool__to beint | Unknown. Only one of the union branches is non-callable, which changes the content of the error message below. I decided to add the type annotations instead of updating the expected error messages, since this seems to more accurately reflect the intent of theseNotBoolabletypes.