mirror of https://github.com/astral-sh/ruff
[red-knot] Assignability of class literals to Callables (#17704)
## Summary Subtyping was already modeled, but assignability also needs an explicit branch. Removes 921 ecosystem false positives. ## Test Plan New Markdown tests.
This commit is contained in:
parent
ca4fdf452d
commit
79f8473e51
|
|
@ -529,6 +529,18 @@ c: Callable[[Any], str] = A().f
|
|||
c: Callable[[Any], str] = A().g
|
||||
```
|
||||
|
||||
### Class literal types
|
||||
|
||||
```py
|
||||
from typing import Any, Callable
|
||||
|
||||
c: Callable[[str], Any] = str
|
||||
c: Callable[[str], Any] = int
|
||||
|
||||
# error: [invalid-assignment]
|
||||
c: Callable[[str], Any] = object
|
||||
```
|
||||
|
||||
### Overloads
|
||||
|
||||
`overloaded.pyi`:
|
||||
|
|
|
|||
|
|
@ -1503,6 +1503,13 @@ impl<'db> Type<'db> {
|
|||
}
|
||||
}
|
||||
|
||||
(Type::ClassLiteral(class_literal), Type::Callable(_)) => {
|
||||
if let Some(callable) = class_literal.into_callable(db) {
|
||||
return callable.is_assignable_to(db, target);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
(Type::FunctionLiteral(self_function_literal), Type::Callable(_)) => {
|
||||
self_function_literal
|
||||
.into_callable_type(db)
|
||||
|
|
|
|||
Loading…
Reference in New Issue