Skip to content

Emit diagnostic when a type variable with a default is followed by one without a default #1651

@dhruvmanila

Description

@dhruvmanila
from typing import TypeVar, Generic

T1 = TypeVar("T1", default=int)
T2 = TypeVar("T2")

# TypeError: Type parameter ~T2 without a default follows type parameter with a default
class Foo1(Generic[T1, T2]): ...

# SyntaxError: non-default type parameter 'T4' follows default type parameter
class Foo2[T3 = int, T4]: ...

ty should just focus on the TypeError while the SyntaxError would need to be raised by the parser (astral-sh/ruff#17412 (comment))

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsRelated to reporting of diagnostics.help wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions