Skip to content
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

fix_dict does not wrap enumerate(d.items()) in a list #47

Open
yonran opened this issue Oct 11, 2023 · 0 comments · May be fixed by #48
Open

fix_dict does not wrap enumerate(d.items()) in a list #47

yonran opened this issue Oct 11, 2023 · 0 comments · May be fixed by #48

Comments

@yonran
Copy link

yonran commented Oct 11, 2023

Description

I was reading the source code of fixer_util.py and I noticed that one item enumerate was not like the others in consuming_calls because it does not actually consume the iterable in python 2 or python 3.

For example, fissix leaves this unchanged (without wrapping in list()) because it thinks that enumerate will consume the python 3 iterable: enumerate(d.items()). But it should wrap it in list because you might mutate d inside a loop: for i, x in enumerate(d.items()): del d[x] which will raise “RuntimeError: dictionary changed size during iteration” in python 3.

Instead, enumerate should be handled the same as iter.

Details

  • OS: any
  • Python version: any
  • fissix version: 21.6.6
  • Can you repro on master? yes
  • Can you repro in a clean virtualenv? yes
@yonran yonran linked a pull request Oct 11, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant