question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect C408 rule warning for dict with keyword arguments

See original GitHub issue

The 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:closed
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mvanderleecommented, Jun 3, 2021

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.

1reaction
adamchainzcommented, Oct 23, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found