WPS425 boolean non-keyword argument clashes with setdefault
See original GitHub issueBug report
What’s wrong
example_dict = {}
example_dict.setdefault("value", True)
>>> WPS425 Found boolean non-keyword argument
example_dict = {}
example_dict.setdefault("value", default=True)
>>> TypeError: setdefault() takes no keyword arguments
How is that should be
Not sure. Maybe there should be a whitelist of allowed methods/functions?
System information
Python 3.7.4
flake8 information
Contents of flake8 --bug-report
:
flake info
{
"dependencies": [
{
"dependency": "entrypoints",
"version": "0.3"
}
],
"platform": {
"python_implementation": "CPython",
"python_version": "3.7.4",
"system": "Darwin"
},
"plugins": [
{
"is_local": false,
"plugin": "flake8-annotations-complexity",
"version": "0.0.2"
},
{
"is_local": false,
"plugin": "flake8-bandit",
"version": "2.1.2"
},
{
"is_local": false,
"plugin": "flake8-blind-except",
"version": "0.1.1"
},
{
"is_local": false,
"plugin": "flake8-broken-line",
"version": "0.1.1"
},
{
"is_local": false,
"plugin": "flake8-bugbear",
"version": "19.8.0"
},
{
"is_local": false,
"plugin": "flake8-comprehensions",
"version": "3.1.4"
},
{
"is_local": false,
"plugin": "flake8-darglint",
"version": "0.4.1"
},
{
"is_local": false,
"plugin": "flake8-debugger",
"version": "3.2.1"
},
{
"is_local": false,
"plugin": "flake8-docstrings",
"version": "1.5.0, pydocstyle: 5.0.1"
},
{
"is_local": false,
"plugin": "flake8-eradicate",
"version": "0.2.3"
},
{
"is_local": false,
"plugin": "flake8-executable",
"version": "2.0.3"
},
{
"is_local": false,
"plugin": "flake8-print",
"version": "3.1.4"
},
{
"is_local": false,
"plugin": "flake8-return",
"version": "0.1.3"
},
{
"is_local": false,
"plugin": "flake8-string-format",
"version": "0.2.3"
},
{
"is_local": false,
"plugin": "flake8_builtins",
"version": "1.4.1"
},
{
"is_local": false,
"plugin": "flake8_coding",
"version": "1.3.2"
},
{
"is_local": false,
"plugin": "flake8_commas",
"version": "2.0.0"
},
{
"is_local": false,
"plugin": "flake8_isort",
"version": "2.3"
},
{
"is_local": false,
"plugin": "flake8_pep3101",
"version": "1.2.1"
},
{
"is_local": false,
"plugin": "flake8_quotes",
"version": "2.1.1"
},
{
"is_local": false,
"plugin": "logging-format",
"version": "0.6.0"
},
{
"is_local": false,
"plugin": "mccabe",
"version": "0.6.1"
},
{
"is_local": false,
"plugin": "naming",
"version": "0.9.1"
},
{
"is_local": false,
"plugin": "pycodestyle",
"version": "2.5.0"
},
{
"is_local": false,
"plugin": "pyflakes",
"version": "2.1.1"
},
{
"is_local": false,
"plugin": "pylint",
"version": "2.4.4"
},
{
"is_local": false,
"plugin": "radon",
"version": "2.4.0"
},
{
"is_local": false,
"plugin": "rst-docstrings",
"version": "0.0.12"
},
{
"is_local": false,
"plugin": "wemake-python-styleguide",
"version": "0.13.2"
}
],
"version": "3.7.9"
}
Related #1085
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
python - setdefault() takes no keyword arguments
Set default should be used like: mydict.setdefault(key, defaultvalue). Don't use kwargs, just provide teh default as the second argument.
Read more >*args and **kwargs in Python - GeeksforGeeks
Python program to illustrate **kwargs for a variable number of keyword arguments with one extra argument. All the same, but one change is...
Read more >Python parameters primer
Positional-only parameters It's to avoid clashes with keyword arguments. What do I mean by that?
Read more >How to use *args and **kwargs in Python
Here is an example of how to use the non-keyworded form. This example passes one formal (positional) argument, and two more variable length ......
Read more >10 Examples to Master *args and **kwargs in Python
Functions are building blocks in Python. They take zero or more arguments and return a value. Python is pretty flexible in terms of...
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
We are going to allow one-argument booleans in the next release: https://github.com/wemake-services/wemake-python-styleguide/pull/1114
The problem is that Python API is inconsistent as f. They actually had to create
/
params to fix it.Why I don’t like to create any kind of whitelist here: it is really hard to cover all cases correctly. For example: one can have
def setdefault(self, key, default):
in their own class. And it would be a violation not to provide a keyword here. So, we cannot be sure when we are based on names, not types.I am going to work on this soon enough, I have a working prototype of type inferring mechanism that works for our case.
Another option is to just turn off this check.