mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00:00
[ty] Add more regression tests for tuple
(#19974)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
This commit is contained in:
parent
0cb1abc1fc
commit
3314cf90ed
2 changed files with 40 additions and 0 deletions
|
@ -630,5 +630,34 @@ class C[T](C): ...
|
||||||
class D[T](D[int]): ...
|
class D[T](D[int]): ...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Tuple as a PEP-695 generic class
|
||||||
|
|
||||||
|
Our special handling for `tuple` does not break if `tuple` is defined as a PEP-695 generic class in
|
||||||
|
typeshed:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[environment]
|
||||||
|
python-version = "3.12"
|
||||||
|
typeshed = "/typeshed"
|
||||||
|
```
|
||||||
|
|
||||||
|
`/typeshed/stdlib/builtins.pyi`:
|
||||||
|
|
||||||
|
```pyi
|
||||||
|
class tuple[T]: ...
|
||||||
|
```
|
||||||
|
|
||||||
|
`/typeshed/stdlib/typing_extensions.pyi`:
|
||||||
|
|
||||||
|
```pyi
|
||||||
|
def reveal_type(obj, /): ...
|
||||||
|
```
|
||||||
|
|
||||||
|
`main.py`:
|
||||||
|
|
||||||
|
```py
|
||||||
|
reveal_type((1, 2, 3)) # revealed: tuple[Literal[1], Literal[2], Literal[3]]
|
||||||
|
```
|
||||||
|
|
||||||
[crtp]: https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
|
[crtp]: https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
|
||||||
[f-bound]: https://en.wikipedia.org/wiki/Bounded_quantification#F-bounded_quantification
|
[f-bound]: https://en.wikipedia.org/wiki/Bounded_quantification#F-bounded_quantification
|
||||||
|
|
|
@ -223,6 +223,17 @@ def _[T](x: A | B):
|
||||||
reveal_type(x) # revealed: A[int] | B
|
reveal_type(x) # revealed: A[int] | B
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Narrowing for tuple
|
||||||
|
|
||||||
|
An early version of <https://github.com/astral-sh/ruff/pull/19920> caused us to crash on this:
|
||||||
|
|
||||||
|
```py
|
||||||
|
def _(val):
|
||||||
|
if type(val) is tuple:
|
||||||
|
# TODO: better would be `Unknown & tuple[object, ...]`
|
||||||
|
reveal_type(val) # revealed: Unknown & tuple[Unknown, ...]
|
||||||
|
```
|
||||||
|
|
||||||
## Limitations
|
## Limitations
|
||||||
|
|
||||||
```py
|
```py
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue