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

WPS425 boolean non-keyword argument clashes with setdefault #1109

Closed
AlwxSin opened this issue Jan 16, 2020 · 7 comments
Closed

WPS425 boolean non-keyword argument clashes with setdefault #1109

AlwxSin opened this issue Jan 16, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@AlwxSin
Copy link
Contributor

AlwxSin commented Jan 16, 2020

Bug 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

@AlwxSin AlwxSin added the bug Something isn't working label Jan 16, 2020
@sobolevn
Copy link
Member

My recommendation is just to ignore (noqa) this case.

@AlwxSin
Copy link
Contributor Author

AlwxSin commented Jan 16, 2020

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.

@sobolevn
Copy link
Member

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.

@sobolevn
Copy link
Member

This will be fixed in typed-linter one day.

@memery-rbx
Copy link

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.

@sobolevn
Copy link
Member

We are going to allow one-argument booleans in the next release: #1114

@memery-rbx
Copy link

Wonderful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants