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
Not sure. Maybe there should be a whitelist of allowed methods/functions?
Python 3.7.4
Contents of flake8 --bug-report:
flake info
json
{
"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
My recommendation is just to ignore (noqa) this case.
I can't agree with that. Ignoring is an option if I have choices. Python linter should not violate python api itself if this api is allowed.
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.
This will be fixed in typed-linter one day.
This isn't worth opening a new Issue, but I found similar behavior when appending booleans to a list, like: a_list.append(True). Using the keyword argument object causes an error. If anyone finds this comment and doesn't want to use noqa, you can use a_list.extend([True]) as a workaround.
We are going to allow one-argument booleans in the next release: https://github.com/wemake-services/wemake-python-styleguide/pull/1114
Wonderful!