Rule UP040 incorrect fix when TypeVar
is used multiple times
#9904
Labels
bug
Something isn't working
TypeVar
is used multiple times
#9904
Initial code
This is code in stub file
decorators.pyi
:Ruff command
After running ruff with command:
TypeVar
is replaced to generic type alias.Code after fix
The code after change is:
What is wrong
Type alias
_Decorator
has two declarations with same name_BaseFun
which is incorrect syntax.The PEP 695 states:
Possible fix
Need to check for duplicates.
Ruff version
ruff 0.2.1
Additional thinking
Not required to this issue, but it may be worth to notify user about remaining, old
TypeVar
or even remove it when rule UP040 is applying.Although the variable is not used anymore, it remains in code, possibly unnoticed (I assume that currently only stubs are processed for this rule, but in future it may change).
The old object remains in global scope, which is not detected by most linters/type checkers.
The text was updated successfully, but these errors were encountered: