-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dict.items() not converted to list(dict.items()) when iterated over #176
Comments
There isn't a command-line option or anything, but it looks like modernize is modifying the handling from 2to3 slightly to assume |
@takluyver Thanks for the help. I saw this part of the source, but my question (and this issue) is about enabling this without modifying the source, for the sake of others who encounter this issue. I would also argue that the default is incorrect and should be changed because it breaks correct code, as shown in the issue description. But this might be a matter of opinion, and explicit opt-out would certainly work for us. |
modernize generally doesn't go in for a lot of options - what you can do is mostly enable and disable specific fixers. You could always disable this one and run the one from 2to3, or one you've customised. Thinking about it, there was a push a while back to make modernize idempotent, so running it on code you had already modernize-d wouldn't produce further changes. I guess this override was part of that, because without it |
@takluyver The idempotence argument would also require |
It appears that
python-modernize
doesn't convertfor k, v in d.items()
tofor k, v in list(d.items())
, assuming that the use ofitems()
was an accident in Python 2. This is not always the case - consider the following two functions:When
python-modernize
is run on the code, it correctly modifiesfoo1
to returnlist(d.items())
, but it doesn't modifyfoo2
to iterate overlist(d.items())
. In our code base this led to many subtle bugs because our Python 2 code was very careful to only useitems()
(andkeys()
andvalues()
) because the dictionary was being modified.Is there a way to opt out of the special-handling of
items
insidefor
?The text was updated successfully, but these errors were encountered: