Skip to content

Commit a52486f

Browse files
committed
Special-case ClassLiteral | ClassLiteral
1 parent 5239fa9 commit a52486f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

crates/red_knot_python_semantic/resources/mdtest/binary/classes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ python-version = "3.10"
1313
class A: ...
1414
class B: ...
1515

16-
reveal_type(A | B) # revealed: UnionType
16+
reveal_type(A | B) # revealed: Literal[A, B]
1717
```
1818

1919
## Union of two classes (prior to 3.10)

crates/red_knot_python_semantic/src/types/infer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use crate::types::{
7070
};
7171
use crate::unpack::Unpack;
7272
use crate::util::subscript::{PyIndex, PySlice};
73-
use crate::Db;
73+
use crate::{Db, Program, PythonVersion};
7474

7575
use super::context::{InferContext, WithDiagnostics};
7676
use super::diagnostic::{
@@ -3361,6 +3361,12 @@ impl<'db> TypeInferenceBuilder<'db> {
33613361
(Type::Never, _, _) | (_, Type::Never, _) => Some(Type::Never),
33623362
(Type::Unknown, _, _) | (_, Type::Unknown, _) => Some(Type::Unknown),
33633363

3364+
(Type::ClassLiteral(_), Type::ClassLiteral(_), ast::Operator::BitOr)
3365+
if Program::get(self.db()).python_version(self.db()) >= PythonVersion::PY310 =>
3366+
{
3367+
Some(UnionType::from_elements(self.db(), [left_ty, right_ty]))
3368+
}
3369+
33643370
(Type::IntLiteral(n), Type::IntLiteral(m), ast::Operator::Add) => Some(
33653371
n.checked_add(m)
33663372
.map(Type::IntLiteral)

0 commit comments

Comments
 (0)