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

False positive on C404 #194

Closed
schinckel opened this issue Nov 13, 2019 · 2 comments · Fixed by #195
Closed

False positive on C404 #194

schinckel opened this issue Nov 13, 2019 · 2 comments · Fixed by #195

Comments

@schinckel
Copy link

I have a block of code that looks like:

instance_kwargs = dict([
    key_value.split('=')
    key_value in full_lookup.split(':')[1].split('&')
])

This is being marked as C404: unnecessary list comprehension.

However, I don't believe it's possible to use a single dict comprehension to perform this.

(I'm not saying it's great code, btw...)

@adamchainz
Copy link
Owner

Thanks. You should be able to use a generator to get around this for the time being

In [1]: x = 'a=1;b=2'

In [2]: dict([i.split('=') for i in x.split(';')])
Out[2]: {'a': '1', 'b': '2'}

In [3]: dict((i.split('=') for i in x.split(';')))
Out[3]: {'a': '1', 'b': '2'}

adamchainz added a commit that referenced this issue Nov 13, 2019
adamchainz added a commit that referenced this issue Nov 13, 2019
@adamchainz
Copy link
Owner

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.

2 participants