From 790cce4628ffb6712aaf98c61f9675dcac52b42a Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Tue, 12 Aug 2025 12:17:40 -0700 Subject: [PATCH] wiring up NewType calls --- crates/ty_python_semantic/src/types.rs | 14 ++++++++++++++ crates/ty_python_semantic/src/types/call/bind.rs | 16 ++++++++++++++++ crates/ty_python_semantic/src/types/infer.rs | 1 + 3 files changed, 31 insertions(+) diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 3440ee58b0..3796a2d1e9 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -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: diff --git a/crates/ty_python_semantic/src/types/call/bind.rs b/crates/ty_python_semantic/src/types/call/bind.rs index e064212225..e7b59366c5 100644 --- a/crates/ty_python_semantic/src/types/call/bind.rs +++ b/crates/ty_python_semantic/src/types/call/bind.rs @@ -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, + ))); + } + _ => {} + }, + _ => {} }, diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 201dcd7500..c5612164d0 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -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`,