Incorrect C408 rule warning for dict with keyword arguments
See original GitHub issueThe C408 rule seems to fail on a dict with keyword arguments, but from the description of the rule, it should not fail.
$ cat scratch.py
a = dict(one=1, two=2, three=3)
$ flake8 --version
3.8.2 (flake8-bugbear: 20.1.4, flake8-comprehensions: 3.2.2, mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes: 2.2.0) CPython 3.8.2
on Darwin
$ flake8 ~/Library/Preferences/PyCharmCE2019.3/scratches/scratch.py
scratch.py:1:5: C408 Unnecessary dict call - rewrite as a literal.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Passing a dictionary to a function as keyword parameters
How to use a dictionary with more keys than function arguments: A solution to #3, above, is to accept (and ignore) additional kwargs...
Read more >Odd error message when kwargs passed as **dict · Issue #5382
I've hit the same issue with passing a dict of kwargs. ... Incorrect handling of kwargs when default values are present #5809.
Read more >Code Style - The Hitchhiker's Guide to Python - Read the Docs
The arbitrary keyword argument dictionary is the last way to pass arguments to functions. If the function requires an undetermined series of named...
Read more >Writing better Python code, automatically - mje.nz
Flake8 catches the problem, warning F841 local variable 'cfg' is assigned to but never ... flake8-comprehensions (allow dict() calls) C408, ...
Read more >Functions and Their Parameters - ICS, UCI
The positional arguments must be listed first when calling a function, mainly because any other rule would be unnecessarily confusing. Keyword arguments ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I only just discovered this great tool, but I’d prefer C408 to be split into 2 distinct rules. One for empty items and one for dict with keyword-only arguments. That way one could be disabled without affecting the other.
I’ve restored the check for
dict()
being called with keyword-only arguments in #282, because I also missed it! Released in version 3.3.0.