You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bugSomething isn't workingfixesRelated to suggested fixes for violationspreviewRelated to preview mode featuresruleImplementing or modifying a lint rule
The automatic fix for RUF052 is unsafe when applied to TypeVar definitions. It renames _T = TypeVar("_T") to T = TypeVar("_T") resulting in invalid code. The TypeVar name string must match the assigned variable name to maintain correctness, and the resulting T = TypeVar("_T") violates this requirement.
The underscore is often used to indicate private or internal TypeVars and is a common and valid pattern in python.
The text was updated successfully, but these errors were encountered:
dylwil3
added
bug
Something isn't working
rule
Implementing or modifying a lint rule
fixes
Related to suggested fixes for violations
preview
Related to preview mode features
labels
Dec 5, 2024
Yes, very similar. Not sure how relevant it is, but the exact point where it broke the test involves _T being passed as an argument to a FUT within a context (pytest.raises in this case).
Great, thanks. I'd argue that this is within the purview of RUF052 -- since the TypeVar is a local variable, it's private to the function even without the underscore; leading underscores are more usually used to indicate unused variables in function scopes, I think.
However, we obviously shouldn't be breaking TypeVar definitions by changing the name the TypeVar is assigned to without changing the string passed into the constructor. We either need to make our renaming logic more sophisticated and/or mark the autofix as unsafe in more cases.
bugSomething isn't workingfixesRelated to suggested fixes for violationspreviewRelated to preview mode featuresruleImplementing or modifying a lint rule
The automatic fix for RUF052 is unsafe when applied to TypeVar definitions. It renames
_T = TypeVar("_T")
toT = TypeVar("_T")
resulting in invalid code. The TypeVar name string must match the assigned variable name to maintain correctness, and the resulting T = TypeVar("_T") violates this requirement.The underscore is often used to indicate private or internal TypeVars and is a common and valid pattern in python.
The text was updated successfully, but these errors were encountered: