-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Don't special-case class instances in binary expression inference #15161
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
15 commits
Select commit
Hold shift + click to select a range
c8c99f6
Regroup literal cases together
dcreager 58ada96
Add Todo and Never cases
dcreager 029932d
General Instance fallback
dcreager 3b1622f
Add a slew of tests
dcreager 33409ba
Linter
dcreager 9fb3013
Add mis-typed test
dcreager f4a65c2
More recursive class definitions cause panics
dcreager a5f0dad
Add test case for class union
dcreager 5239fa9
Add test case for class union < 3.10
dcreager a52486f
Special-case ClassLiteral | ClassLiteral
dcreager dffd23d
Merge branch 'main' into dcreager/infer-binary
dcreager fe73357
Revert "Special-case ClassLiteral | ClassLiteral"
dcreager a70fc31
Move subclass tests to be closer to similar class tests
dcreager 0acdbe4
Add reflected dunder test cases
dcreager 7149f42
Merge branch 'main' into dcreager/infer-binary
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
27 changes: 27 additions & 0 deletions
27
crates/red_knot_python_semantic/resources/mdtest/binary/classes.md
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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Binary operations on classes | ||
|
|
||
| ## Union of two classes | ||
|
|
||
| Unioning two classes via the `|` operator is only available in Python 3.10 and later. | ||
|
|
||
| ```toml | ||
| [environment] | ||
| python-version = "3.10" | ||
| ``` | ||
|
|
||
| ```py | ||
| class A: ... | ||
| class B: ... | ||
|
|
||
| reveal_type(A | B) # revealed: UnionType | ||
| ``` | ||
|
|
||
| ## Union of two classes (prior to 3.10) | ||
|
|
||
| ```py | ||
| class A: ... | ||
| class B: ... | ||
|
|
||
| # error: "Operator `|` is unsupported between objects of type `Literal[A]` and `Literal[B]`" | ||
| reveal_type(A | B) # revealed: Unknown | ||
| ``` | ||
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.
Uh oh!
There was an error while loading. Please reload this page.