From 0e57f7f4a9e35b7e17fdef7ad2d74d479764717c Mon Sep 17 00:00:00 2001 From: Matthew Mckee Date: Tue, 8 Jul 2025 00:53:45 +0100 Subject: [PATCH 1/2] Rename BoundMethodType.into_callable_type to into_callable --- crates/ty_python_semantic/src/types.rs | 4 ++-- crates/ty_python_semantic/src/types/class.rs | 2 +- crates/ty_python_semantic/src/types/function.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 4eb6d9207adf4..d2c9c8a88f374 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -1104,7 +1104,7 @@ impl<'db> Type<'db> { Type::FunctionLiteral(function_literal) => { Some(Type::Callable(function_literal.into_callable_type(db))) } - Type::BoundMethod(bound_method) => Some(bound_method.into_callable_type(db)), + Type::BoundMethod(bound_method) => Some(bound_method.into_callable(db)), Type::NominalInstance(_) | Type::ProtocolInstance(_) => { let call_symbol = self @@ -7166,7 +7166,7 @@ fn walk_bound_method_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( } impl<'db> BoundMethodType<'db> { - pub(crate) fn into_callable_type(self, db: &'db dyn Db) -> Type<'db> { + pub(crate) fn into_callable(self, db: &'db dyn Db) -> Type<'db> { Type::Callable(CallableType::new( db, CallableSignature::from_overloads( diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index a1104beeed391..14e0935ecf30c 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -602,7 +602,7 @@ impl<'db> ClassType<'db> { // https://typing.python.org/en/latest/spec/constructors.html#converting-a-constructor-to-callable // by always respecting the signature of the metaclass `__call__`, rather than // using a heuristic which makes unwarranted assumptions to sometimes ignore it. - return metaclass_dunder_call_function.into_callable_type(db); + return metaclass_dunder_call_function.into_callable(db); } let dunder_new_function_symbol = self_ty diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 0a814f8e13470..189ea9dd12793 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -766,7 +766,7 @@ impl<'db> FunctionType<'db> { self.literal(db).signature(db, self.type_mappings(db)) } - /// Convert the `FunctionType` into a [`Type::Callable`]. + /// Convert the `FunctionType` into a [`CallableType`]. pub(crate) fn into_callable_type(self, db: &'db dyn Db) -> CallableType<'db> { CallableType::new(db, self.signature(db), false) } From 01101c4711553683c954c0de2dbbd8d6a966ad0c Mon Sep 17 00:00:00 2001 From: Matthew Mckee Date: Tue, 8 Jul 2025 20:23:38 +0100 Subject: [PATCH 2/2] make BoundMethodType.into_callable_type return CallableType --- crates/ty_python_semantic/src/types.rs | 10 ++++++---- crates/ty_python_semantic/src/types/class.rs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index d2c9c8a88f374..91ff6c388a2bb 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -1104,7 +1104,9 @@ impl<'db> Type<'db> { Type::FunctionLiteral(function_literal) => { Some(Type::Callable(function_literal.into_callable_type(db))) } - Type::BoundMethod(bound_method) => Some(bound_method.into_callable(db)), + Type::BoundMethod(bound_method) => { + Some(Type::Callable(bound_method.into_callable_type(db))) + } Type::NominalInstance(_) | Type::ProtocolInstance(_) => { let call_symbol = self @@ -7166,8 +7168,8 @@ fn walk_bound_method_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( } impl<'db> BoundMethodType<'db> { - pub(crate) fn into_callable(self, db: &'db dyn Db) -> Type<'db> { - Type::Callable(CallableType::new( + pub(crate) fn into_callable_type(self, db: &'db dyn Db) -> CallableType<'db> { + CallableType::new( db, CallableSignature::from_overloads( self.function(db) @@ -7177,7 +7179,7 @@ impl<'db> BoundMethodType<'db> { .map(signatures::Signature::bind_self), ), false, - )) + ) } fn normalized_impl(self, db: &'db dyn Db, visitor: &mut TypeTransformer<'db>) -> Self { diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 14e0935ecf30c..05064a190362b 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -602,7 +602,7 @@ impl<'db> ClassType<'db> { // https://typing.python.org/en/latest/spec/constructors.html#converting-a-constructor-to-callable // by always respecting the signature of the metaclass `__call__`, rather than // using a heuristic which makes unwarranted assumptions to sometimes ignore it. - return metaclass_dunder_call_function.into_callable(db); + return Type::Callable(metaclass_dunder_call_function.into_callable_type(db)); } let dunder_new_function_symbol = self_ty