Skip to content

PLC2701 false positive for a private name import used in a type parameter list #24563

@dscorbett

Description

@dscorbett

Summary

The documentation of import-private-name (PLC2701) says it “ignores private name imports that are exclusively used in type annotations”, but that doesn’t include imports used in type parameter lists. Those are type annotations too, so it should ignore them too. Example:

$ cat >plc2701.py <<'# EOF'
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from _typeshed import SupportsRichComparison
def f[T: SupportsRichComparison](x: T, y: T):
    return x < y or x > y
# EOF

$ ruff --isolated check --select PLC2701 --preview plc2701.py --output-format concise
plc2701.py:4:10: error[PLC2701] Private name import `_typeshed`
Found 1 error.

Version

ruff 0.15.10 (252f761 2026-04-09)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions