Closed
Description
Description
Ruff gives undefined-name (F821) error for unquoted forward reference in typing.TypeVar
default
parameter in .pyi type stub.
TypeVar
has a new parameter default
in Python 3.13, which accepts a type.
From what I understand, unquoted forward references should be allowed everywhere in type stubs. This has already been fixed for the bound
parameter, it seems -- F821 is not reported for unquoted forward reference used in bound
parameter. I think default
should be treated the same way as bound
.
Example .pyi
type stub:
from typing import TypeVar
_P = TypeVar("_P", bound=X, default=X)
#^ F821
# The `bound` parameter does not cause an error, only `default` parameter
_Q = TypeVar("_Q", bound=X) # (no error)
class X:
...