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
Generating a new, unique variable name is trivial, but it does, however, necessitate the fix being marked as unsafe to give the user a chance to review that name (along with everything else).
The text was updated successfully, but these errors were encountered:
@MichaReiser Generating a new name can never fail: Ruff just needs to check all names of the form var_{number} from 0 to infinity, stopping as soon as it finds one available (I think I did this once in a PR).
The examples above are all about global/nonlocal, but the same also applies to subscripts and attributes.
The point of UP028 is to recommend yield from where possible. The fix proposed here doesn’t use yield from so it isn’t an appropriate fix for UP028: it only fixes it in that it adds an extra statement to the loop so UP028 doesn’t apply. It could be an appropriate fix for a new style rule against assigning to globals via for targets, which is unrelated to yield.
After #16451,
UP028
is no longer always fixable. However, a different kind of fix can be offered in such cases:I can't think of any edge cases, other than that adding a new name to the scope might break runtime inspections:
Also consider the case where the new name is the same as an existing one:
Generating a new, unique variable name is trivial, but it does, however, necessitate the fix being marked as unsafe to give the user a chance to review that name (along with everything else).
The text was updated successfully, but these errors were encountered: