Summary
The preview UP040 fix can emit an invalid PEP 695 type-parameter order when a defaulted TypeVar is followed by a non-defaulted TypeVar.
Playground reproduction
from typing import TypeAlias, TypeVar
T = TypeVar("T", default=int)
S = TypeVar("S")
Pair: TypeAlias = tuple[T, S]
With --target-version py313 --preview --select UP040 --unsafe-fixes, Ruff produces:
type Pair[T = int, S] = tuple[T, S]
Ruff then rejects its own output:
invalid-syntax: non default type parameter `S` follows default type parameter
UP040 should not offer a fix in this case unless it can generate a valid and equivalent type-parameter list. This blocks #26948.
This also affects UP046 and UP047.
Summary
The preview UP040 fix can emit an invalid PEP 695 type-parameter order when a defaulted
TypeVaris followed by a non-defaultedTypeVar.Playground reproduction
With
--target-version py313 --preview --select UP040 --unsafe-fixes, Ruff produces:Ruff then rejects its own output:
invalid-syntax: non default type parameter `S` follows default type parameterUP040 should not offer a fix in this case unless it can generate a valid and equivalent type-parameter list. This blocks #26948.
This also affects UP046 and UP047.