flake8-comprehensions icon indicating copy to clipboard operation
flake8-comprehensions copied to clipboard

Extend C41x to detect for _ in list(dict.values())

Open Lattay opened this issue 4 years ago • 2 comments

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).

Lattay avatar Dec 04 '20 16:12 Lattay

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

adamchainz avatar Dec 04 '20 17:12 adamchainz

Thank you, I never done flake8 plug-ins before butI'll look into it.

Lattay avatar Dec 06 '20 10:12 Lattay