Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ntBre opened this issue Feb 4, 2025 · 0 comments · Fixed by #15999
Closed

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

ntBre opened this issue Feb 4, 2025 · 0 comments · Fixed by #15999
Labels
fixes Related to suggested fixes for violations good first issue Good for newcomers help wanted Contributions especially welcome

Comments

@ntBre
Copy link
Contributor

ntBre commented Feb 4, 2025

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.

@ntBre ntBre added fixes Related to suggested fixes for violations good first issue Good for newcomers help wanted Contributions especially welcome labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixes Related to suggested fixes for violations good first issue Good for newcomers help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant