Skip to content

Commit 1317b0b

Browse files
committed
Propagate is_function_like through decorators
1 parent 342e85c commit 1317b0b

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

crates/ty_python_semantic/resources/mdtest/call/callables_as_descriptors.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,5 @@ class C:
130130

131131
C().method(1)
132132

133-
# TODO: We shouldn't issue any errors here
134-
# error: [missing-argument]
135-
# error: [invalid-argument-type]
136133
C().method_decorated(1)
137134
```

crates/ty_python_semantic/src/types.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,13 @@ impl<'db> Type<'db> {
998998
}
999999
}
10001000

1001+
pub(crate) const fn unwrap_as_callable_type(self) -> Option<CallableType<'db>> {
1002+
match self {
1003+
Type::Callable(callable_type) => Some(callable_type),
1004+
_ => None,
1005+
}
1006+
}
1007+
10011008
pub(crate) const fn expect_dynamic(self) -> DynamicType<'db> {
10021009
self.into_dynamic()
10031010
.expect("Expected a Type::Dynamic variant")

crates/ty_python_semantic/src/types/infer/builder.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,23 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
21742174
.try_call(self.db(), &CallArguments::positional([inferred_ty]))
21752175
.map(|bindings| bindings.return_type(self.db()))
21762176
{
2177-
Ok(return_ty) => return_ty,
2177+
Ok(return_ty) => {
2178+
let is_input_function_like = inferred_ty.is_function_literal()
2179+
|| inferred_ty
2180+
.unwrap_as_callable_type()
2181+
.is_some_and(|callable| callable.is_function_like(self.db()));
2182+
if is_input_function_like
2183+
&& let Some(callable_type) = return_ty.unwrap_as_callable_type()
2184+
{
2185+
Type::Callable(CallableType::new(
2186+
self.db(),
2187+
callable_type.signatures(self.db()),
2188+
true,
2189+
))
2190+
} else {
2191+
return_ty
2192+
}
2193+
}
21782194
Err(CallError(_, bindings)) => {
21792195
bindings.report_diagnostics(&self.context, (*decorator_node).into());
21802196
bindings.return_type(self.db())

0 commit comments

Comments
 (0)