mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Fix CallableTypeOf
display signature (#17235)
This commit is contained in:
parent
3dd6d0a422
commit
73a9974d8a
3 changed files with 12 additions and 3 deletions
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue