mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:14:52 +00:00
[ty] Fallback to Unknown if no type is stored for an expression (#19517)
## Summary See discussion at https://github.com/astral-sh/ruff/pull/19478/files#r2223870292 Fixes https://github.com/astral-sh/ty/issues/865 ## Test Plan Added one mdtest for invalid Callable annotation; removed `pull-types: skip` from that test file. Co-authored-by: lipefree <willy.ngo.2000@gmail.com>
This commit is contained in:
parent
c8c80e054e
commit
ae9d450b5f
3 changed files with 28 additions and 35 deletions
|
@ -58,8 +58,6 @@ def _(c: Callable[[int, 42, str, False], None]):
|
|||
|
||||
### Missing return type
|
||||
|
||||
<!-- pull-types:skip -->
|
||||
|
||||
Using a parameter list:
|
||||
|
||||
```py
|
||||
|
@ -90,6 +88,21 @@ def _(c: Callable[ # error: [invalid-type-form] "Special form `typing.Callable`
|
|||
reveal_type(c) # revealed: (...) -> Unknown
|
||||
```
|
||||
|
||||
### Invalid parameters and return type
|
||||
|
||||
```py
|
||||
from typing import Callable
|
||||
|
||||
# fmt: off
|
||||
|
||||
def _(c: Callable[
|
||||
# error: [invalid-type-form] "Int literals are not allowed in this context in a type expression"
|
||||
{1, 2}, 2 # error: [invalid-type-form] "The first argument to `Callable` must be either a list of types, ParamSpec, Concatenate, or `...`"
|
||||
]
|
||||
):
|
||||
reveal_type(c) # revealed: (...) -> Unknown
|
||||
```
|
||||
|
||||
### More than two arguments
|
||||
|
||||
We can't reliably infer the callable type if there are more then 2 arguments because we don't know
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue