mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00

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.
486 B
486 B
Binary operations on classes
Union of two classes
Unioning two classes via the |
operator is only available in Python 3.10 and later.
[environment]
python-version = "3.10"
class A: ...
class B: ...
reveal_type(A | B) # revealed: UnionType
Union of two classes (prior to 3.10)
class A: ...
class B: ...
# error: "Operator `|` is unsupported between objects of type `Literal[A]` and `Literal[B]`"
reveal_type(A | B) # revealed: Unknown