-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't special-case class instances in binary expression inference (#1…
…5161) Just like in #15045 for unary expressions: In binary expressions, we were only looking for dunder expressions for `Type::Instance` types. We had some special cases for coercing the various `Literal` types into their corresponding `Instance` types before doing the lookup. But we can side-step all of that by using the existing `Type::to_meta_type` and `Type::to_instance` methods.
- Loading branch information
Showing
8 changed files
with
555 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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 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.