A TypeVar, ParamSpec, TypeVarTuple or NewType is given a name that differs from the variable it is assigned to

tx0/python:type-variable-name-mismatchdefaultwarningbug

What it finds

T = TypeVar("U") makes a type variable that calls itself U in error messages and in repr, while the code calls it T; type checkers reject the assignment. The string has to repeat the variable's name, as it does for ParamSpec, TypeVarTuple and NewType.

From the rule's source, type_variable_name_mismatch.rs.

Example from the rule's tests
from typing import NewType, ParamSpec, TypeVarimport typing T = TypeVar("U")tx0 reports: the TypeVar assigned to T is named UP = ParamSpec("P")UserId = NewType("UserID", int)tx0 reports: the NewType assigned to UserId is named UserIDK = typing.TypeVar("K", bound=str)V_co = TypeVar("V_co", covariant=True)
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/python:type-variable-name-mismatch" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:type-variable-name-mismatch] reason="..."

tx0 explain tx0/python:type-variable-name-mismatch shows the same in the terminal. Found a false positive? Report it.