Skip to content

F821 false positive for TypeVar default parameter unquoted forward reference in type stub (.pyi) #15677

Closed
@x11x

Description

@x11x

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:
    ...

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions