Skip to content

[flake8-pyi] Add autofix for unused-private-type-var (PYI018) #15940

@ntBre

Description

@ntBre

We currently offer a diagnostic for unused private type variables like these:

import typing
import typing_extensions

_T = typing.TypeVar("_T")
_Ts = typing_extensions.TypeVarTuple("_Ts")

But it would be nice to offer a fix to delete them too. This came up in #15682 because a PYI018 autofix would finish the transformation of pre-PEP-695 code like this:

from typing import Generic, TypeVar

_T = TypeVar("_T")

class Foo(Generic[_T]):
    var: _T

to

class Foo[T]:
    var: T

by converting from Generic + standalone TypeVar to PEP-695 generics (UP046, renaming the private generic (UP051), and then removing the now-unused private type variable (PYI018 after this issue).

The function implementing this rule can be found here. I think delete_stmt may help with the implementation, with some examples of its usage here and here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixesRelated to suggested fixes for violationsgood first issueGood for newcomershelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions