wiring up NewType calls

This commit is contained in:
Jack O'Connor 2025-08-12 12:17:40 -07:00
parent 24f6d2dc13
commit 790cce4628
3 changed files with 31 additions and 0 deletions

View File

@ -4257,6 +4257,20 @@ impl<'db> Type<'db> {
.into()
}
Some(KnownClass::NewType) => Binding::single(
self,
Signature::new(
Parameters::new([
Parameter::positional_or_keyword(Name::new_static("name"))
.with_annotated_type(Type::LiteralString),
Parameter::positional_or_keyword(Name::new_static("tp")),
]),
// TODO: What should this return type be?
Some(KnownClass::NewType.to_instance(db)),
),
)
.into(),
Some(KnownClass::Object) => {
// ```py
// class object:

View File

@ -1056,6 +1056,22 @@ impl<'db> Bindings<'db> {
}
}
Some(KnownClass::NewType) => match overload.parameter_types() {
[Some(Type::StringLiteral(name)), Some(supertype)] => {
let params = DataclassParams::default();
overload.set_return_type(Type::from(ClassLiteral::new(
db,
ast::name::Name::new(name.value(db)),
what_goes_here,
None,
None,
None,
None,
)));
}
_ => {}
},
_ => {}
},

View File

@ -6231,6 +6231,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
| KnownClass::TypeVar
| KnownClass::TypeAliasType
| KnownClass::Deprecated
| KnownClass::NewType
)
) || (
// Constructor calls to `tuple` and subclasses of `tuple` are handled in `Type::Bindings`,