Fix CallableTypeOf display signature (#17235)

This commit is contained in:
Matthew Mckee 2025-04-06 18:12:52 +01:00 committed by GitHub
parent 3dd6d0a422
commit 73a9974d8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 3 deletions

View file

@ -453,6 +453,5 @@ def _(
# TODO: should be `(x: int) -> Foo`
reveal_type(c4) # revealed: (...) -> Foo
# TODO: `self` is bound here; this should probably be `(x: int) -> str`?
reveal_type(c5) # revealed: (self, x: int) -> str
reveal_type(c5) # revealed: (x: int) -> str
```

View file

@ -519,6 +519,10 @@ impl<'db> Type<'db> {
matches!(self, Type::FunctionLiteral(..))
}
pub const fn is_bound_method(&self) -> bool {
matches!(self, Type::BoundMethod(..))
}
pub fn is_union_of_single_valued(&self, db: &'db dyn Db) -> bool {
self.into_union()
.is_some_and(|union| union.elements(db).iter().all(|ty| ty.is_single_valued(db)))

View file

@ -6924,7 +6924,13 @@ impl<'db> TypeInferenceBuilder<'db> {
return Type::unknown();
};
Type::Callable(CallableType::new(db, signature.clone()))
let revealed_signature = if argument_type.is_bound_method() {
signature.bind_self()
} else {
signature.clone()
};
Type::Callable(CallableType::new(db, revealed_signature))
}
},