Open
Description
It appears that python-modernize
doesn't convert for k, v in d.items()
to for k, v in list(d.items())
, assuming that the use of items()
was an accident in Python 2. This is not always the case - consider the following two functions:
def foo1(d):
return d.items()
def foo2(d):
for k, v in d.items():
if v % 2 == 0:
del d[k]
When python-modernize
is run on the code, it correctly modifies foo1
to return list(d.items())
, but it doesn't modify foo2
to iterate over list(d.items())
. In our code base this led to many subtle bugs because our Python 2 code was very careful to only use items()
(and keys()
and values()
) because the dictionary was being modified.
Is there a way to opt out of the special-handling of items
inside for
?
Metadata
Metadata
Assignees
Labels
No labels