flake8-comprehensions
flake8-comprehensions copied to clipboard
Extend C41x to detect for _ in list(dict.values())
Hello, I inherited a code with a lot of pattern like this:
for val in list(some_dict.values()):
do_something(val)
As well as the list comprehension counterpart. As this plugin helped me a lot to catch a lot of other list comprehension and list/set/dict abuse, I wondered if such a pattern could be added to C411 (or another code).
Hi,
Yes, we could do this. I think it would want another code.
I don't have time to look into this right now, but if you make a PR I'll review. To start, check out the ast module in Python's standard library and try parsing some examples to see what the parsed tree looks like for this pattern.
Thanks,
Adam
Thank you, I never done flake8 plug-ins before butI'll look into it.