mirror of
https://github.com/astral-sh/ruff.git
synced 2026-10-28 19:00:26 +08:00
## Summary
We now report a defaulted `TypeVar` anywhere after a `TypeVarTuple` in a
legacy `Generic[...]` or `Protocol[...]` base. The ambiguity persists
when a required parameter comes between them.
```python
from typing import Generic, TypeVar, TypeVarTuple
Ts = TypeVarTuple("Ts")
U = TypeVar("U")
T = TypeVar("T", default=bool)
class C(Generic[*Ts, U, T]): ... # Now an error on T
```
For `C[int, str]`, an empty `Ts` leaves `U = int` and `T = str`. Binding
`int` to `Ts` instead leaves `U = str` and uses the default `T = bool`.
The typing spec describes the adjacent case. We also diagnose the
nonadjacent case, as mypy, Pyright, and Pyrefly do. [Typing
spec](https://typing.python.org/en/latest/spec/generics.html#defaults-following-typevartuple)
Legacy bases and PEP 695 declarations now share a diagnostic that points
to the pack and each later defaulted `TypeVar`. Both allow a defaulted
`ParamSpec`, whose argument list is distinguishable from the types that
fill the pack.
Markdown files within the mdtest/ subdirectory are tests of type inference and type checking;
executed by the tests/mdtest.rs integration test.
See crates/ty_test/README.md for documentation of this test format.