From ef1802b94f3bf7e7afcba2dfb9bd8896e73485c8 Mon Sep 17 00:00:00 2001 From: Matthew Mckee Date: Wed, 6 Aug 2025 23:24:59 +0100 Subject: [PATCH] [ty] Repurpose `FunctionType.into_bound_method_type` to return `BoundMethodType` (#19793) ## Summary As per our naming scheme (at least for callable types) this should return a `BoundMethodType`, or be renamed, but it makes more sense to change the return type. I also ensure `ClassType.into_callable` returns a `Type::Callable` in the changed branch. Ideally we could return a `CallableType` from these `into_callable` functions (and rename to `into_callable_type` but because of unions we cannot do this. --- crates/ty_python_semantic/src/types/class.rs | 6 +++++- crates/ty_python_semantic/src/types/function.rs | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index eff270aeb2..e681b21c8a 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -1044,7 +1044,11 @@ impl<'db> ClassType<'db> { .place; if let Place::Type(Type::FunctionLiteral(new_function), _) = new_function_symbol { - new_function.into_bound_method_type(db, self_ty) + Type::Callable( + new_function + .into_bound_method_type(db, self_ty) + .into_callable_type(db), + ) } else { // Fallback if no `object.__new__` is found. CallableType::single( diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 9feaadb9a4..9447d9991f 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -800,13 +800,13 @@ impl<'db> FunctionType<'db> { CallableType::new(db, self.signature(db), false) } - /// Convert the `FunctionType` into a [`Type::BoundMethod`]. + /// Convert the `FunctionType` into a [`BoundMethodType`]. pub(crate) fn into_bound_method_type( self, db: &'db dyn Db, self_instance: Type<'db>, - ) -> Type<'db> { - Type::BoundMethod(BoundMethodType::new(db, self, self_instance)) + ) -> BoundMethodType<'db> { + BoundMethodType::new(db, self, self_instance) } pub(crate) fn has_relation_to(