From 81e202ed523b2f2e5ddb69b3da3015b112328263 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 14 Feb 2025 07:15:24 +0000 Subject: [PATCH] Make `CallBinding::callable_ty` required (#16135) ## Summary The `callable_ty` is always known except in some TODO code where we can use a `TODO` type instead. ## Test Plan `cargo test` --- crates/red_knot_python_semantic/src/types.rs | 2 +- .../red_knot_python_semantic/src/types/call/bind.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types.rs b/crates/red_knot_python_semantic/src/types.rs index 6d10b10131..e1fe29359c 100644 --- a/crates/red_knot_python_semantic/src/types.rs +++ b/crates/red_knot_python_semantic/src/types.rs @@ -1942,7 +1942,7 @@ impl<'db> Type<'db> { fn call(self, db: &'db dyn Db, arguments: &CallArguments<'_, 'db>) -> CallOutcome<'db> { match self { Type::FunctionLiteral(function_type) => { - let mut binding = bind_call(db, arguments, function_type.signature(db), Some(self)); + let mut binding = bind_call(db, arguments, function_type.signature(db), self); match function_type.known(db) { Some(KnownFunction::RevealType) => { let revealed_ty = binding.one_parameter_type().unwrap_or(Type::unknown()); diff --git a/crates/red_knot_python_semantic/src/types/call/bind.rs b/crates/red_knot_python_semantic/src/types/call/bind.rs index 4a20987ce3..f2fb125d33 100644 --- a/crates/red_knot_python_semantic/src/types/call/bind.rs +++ b/crates/red_knot_python_semantic/src/types/call/bind.rs @@ -5,7 +5,7 @@ use crate::types::diagnostic::{ TOO_MANY_POSITIONAL_ARGUMENTS, UNKNOWN_ARGUMENT, }; use crate::types::signatures::Parameter; -use crate::types::UnionType; +use crate::types::{todo_type, UnionType}; use ruff_python_ast as ast; /// Bind a [`CallArguments`] against a callable [`Signature`]. @@ -16,7 +16,7 @@ pub(crate) fn bind_call<'db>( db: &'db dyn Db, arguments: &CallArguments<'_, 'db>, signature: &Signature<'db>, - callable_ty: Option>, + callable_ty: Type<'db>, ) -> CallBinding<'db> { let parameters = signature.parameters(); // The type assigned to each parameter at this call site. @@ -138,7 +138,7 @@ pub(crate) fn bind_call<'db>( #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct CallBinding<'db> { /// Type of the callable object (function, class...) - callable_ty: Option>, + callable_ty: Type<'db>, /// Return type of the call. return_ty: Type<'db>, @@ -154,7 +154,7 @@ impl<'db> CallBinding<'db> { // TODO remove this constructor and construct always from `bind_call` pub(crate) fn from_return_type(return_ty: Type<'db>) -> Self { Self { - callable_ty: None, + callable_ty: todo_type!("CallBinding::from_return_type"), return_ty, parameter_tys: Box::default(), errors: vec![], @@ -189,8 +189,8 @@ impl<'db> CallBinding<'db> { fn callable_name(&self, db: &'db dyn Db) -> Option<&str> { match self.callable_ty { - Some(Type::FunctionLiteral(function)) => Some(function.name(db)), - Some(Type::ClassLiteral(class_type)) => Some(class_type.class.name(db)), + Type::FunctionLiteral(function) => Some(function.name(db)), + Type::ClassLiteral(class_type) => Some(class_type.class.name(db)), _ => None, } }