File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
crates/ty_python_semantic
resources/mdtest/dataclasses Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -1483,7 +1483,7 @@ def sequence(cls: type[U]) -> type[U]:
14831483 match_args = False ,
14841484 kw_only = True ,
14851485 )(cls )
1486- reveal_type(d) # revealed: type[U@sequence]
1486+ reveal_type(d) # revealed: type[U@sequence] & Any
14871487 return d
14881488
14891489@dataclass_transform (kw_only_default = True )
@@ -1494,7 +1494,7 @@ def sequence2(cls: type) -> type:
14941494 match_args = False ,
14951495 kw_only = True ,
14961496 )(cls )
1497- reveal_type(d) # revealed: type
1497+ reveal_type(d) # revealed: type & Any
14981498 return d
14991499
15001500@dataclass_transform (kw_only_default = True )
@@ -1506,4 +1506,13 @@ def sequence3(cls: type[U]) -> type[U]:
15061506def sequence4 (cls : type ) -> type :
15071507 # TODO : should reveal `type`
15081508 return reveal_type(dataclass(cls )) # revealed: Unknown
1509+
1510+ class Foo : ...
1511+
1512+ ordered_foo = dataclass(order = True )(Foo)
1513+ reveal_type(ordered_foo) # revealed: type[Foo] & Any
1514+ # TODO : should be `Foo & Any`
1515+ reveal_type(ordered_foo()) # revealed: @Todo(Type::Intersection.call)
1516+ # TODO : should be `Any`
1517+ reveal_type(ordered_foo() < ordered_foo()) # revealed: @Todo(Type::Intersection.call)
15091518```
Original file line number Diff line number Diff line change @@ -6195,7 +6195,7 @@ impl<'db> Type<'db> {
61956195 ),
61966196
61976197 Type::Intersection(_) => {
6198- Binding::single(self, Signature::todo("Type::Intersection.call() ")).into()
6198+ Binding::single(self, Signature::todo("Type::Intersection.call")).into()
61996199 }
62006200
62016201 Type::DataclassDecorator(_) => {
@@ -6204,10 +6204,13 @@ impl<'db> Type<'db> {
62046204 let context = GenericContext::from_typevar_instances(db, [typevar]);
62056205 let parameters = [Parameter::positional_only(Some(Name::new_static("cls")))
62066206 .with_annotated_type(typevar_meta)];
6207+ // Intersect with `Any` for the return type to reflect the fact that the `dataclass()`
6208+ // decorator adds methods to the class
6209+ let returns = IntersectionType::from_elements(db, [typevar_meta, Type::any()]);
62076210 let signature = Signature::new_generic(
62086211 Some(context),
62096212 Parameters::new(db, parameters),
6210- Some(typevar_meta ),
6213+ Some(returns ),
62116214 );
62126215 Binding::single(self, signature).into()
62136216 }
You can’t perform that action at this time.
0 commit comments