-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed as not planned
Labels
fixesRelated to suggested fixes for violationsRelated to suggested fixes for violationswishNot on the current roadmap; maybe in the futureNot on the current roadmap; maybe in the future
Description
After #16451, UP028 is no longer always fixable. However, a different kind of fix can be offered in such cases:
for some_global, some_nonlocal in iterable:
yield some_global, some_nonlocalfor _element in iterable:
some_global, some_nonlocal = _element
yield some_global, some_nonlocalI can't think of any edge cases, other than that adding a new name to the scope might break runtime inspections:
nonlocal some_nonlocal
for some_nonlocal in iterable:
yield some_nonlocal
print(locals()) # {'some_nonlocal': ...}nonlocal some_nonlocal
for _element in iterable:
some_nonlocal = _element
yield some_nonlocal
print(locals()) # {'some_nonlocal': ..., '_element': ...}Also consider the case where the new name is the same as an existing one:
_element = ...
for _element in iterable:
some_global, some_nonlocal = _element
yield some_global, some_nonlocal
print(_element) # !!!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).
Metadata
Metadata
Assignees
Labels
fixesRelated to suggested fixes for violationsRelated to suggested fixes for violationswishNot on the current roadmap; maybe in the futureNot on the current roadmap; maybe in the future