wemake-services / wemake-python-styleguide

The strictest and most opinionated python linter ever!
https://wemake-python-styleguide.rtfd.io
MIT License
2.54k stars 378 forks source link

WPS601 false-positive with dataclasses #1431

Closed nsidnev closed 4 years ago

nsidnev commented 4 years ago

Bug report

What's wrong

This code (actually just modified example from the python docs) produces a false positive WPS601 error:

from dataclasses import field, dataclass

@dataclass
class MyDataclass:
    field1: int
    field2: int
    field3: int = field(init=False)

    def __post_init__(self) -> None:
        self.field3 = self.field1 + self.field2  # error here

How is that should be

Well, since this is a dataclass, it seems to me that this error shouldn't occur here.

NOTE: in fact, I am not using python dataclasses, but pydantic dataclasses, but in both cases an error can be reproduced. But if possible, then I'd like that in the case of pydantic usage this error also did not occur.

System information

flake8 information

Contents of flake8 --bug-report:

{ "dependencies": [], "platform": { "python_implementation": "CPython", "python_version": "3.8.3", "system": "Linux" }, "plugins": [ { "is_local": false, "plugin": "flake8-bandit", "version": "2.1.2" }, { "is_local": false, "plugin": "flake8-broken-line", "version": "0.2.0" }, { "is_local": false, "plugin": "flake8-bugbear", "version": "19.8.0" }, { "is_local": false, "plugin": "flake8-comprehensions", "version": "3.2.2" }, { "is_local": false, "plugin": "flake8-darglint", "version": "1.3.0" }, { "is_local": false, "plugin": "flake8-debugger", "version": "3.2.1" }, { "is_local": false, "plugin": "flake8-docstrings", "version": "1.5.0, pydocstyle: 5.0.2" }, { "is_local": false, "plugin": "flake8-eradicate", "version": "0.3.0" }, { "is_local": false, "plugin": "flake8-pytest-style", "version": "1.1.1" }, { "is_local": false, "plugin": "flake8-string-format", "version": "0.2.3" }, { "is_local": false, "plugin": "flake8_commas", "version": "2.0.0" }, { "is_local": false, "plugin": "flake8_isort", "version": "2.9.1" }, { "is_local": false, "plugin": "flake8_quotes", "version": "2.1.2" }, { "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.6.0" }, { "is_local": false, "plugin": "pyflakes", "version": "2.2.0" }, { "is_local": false, "plugin": "rst-docstrings", "version": "0.0.12" }, { "is_local": false, "plugin": "wemake_python_styleguide", "version": "0.14.0" } ], "version": "3.8.2" }

pip information

Contents of pip freeze:

add-trailing-comma==2.0.1 appdirs==1.4.4 argcomplete==1.11.1 astor==0.8.1 attrs==19.3.0 autoflake==1.3.1 bandit==1.6.2 beautifulsoup4==4.9.1 black==19.10b0 certifi==2020.4.5.1 chardet==3.0.4 click==7.1.2 colorama==0.4.1 colorlog==4.1.0 coverage==5.1 coverage-conditional-plugin==0.2.0 darglint==1.3.0 decorator==4.4.2 distlib==0.3.0 docutils==0.16 entrypoints==0.3 eradicate==1.0 fastapi==0.55.1 filelock==3.0.12 flake8==3.8.2 flake8-bandit==2.1.2 flake8-broken-line==0.2.0 flake8-bugbear==19.8.0 flake8-commas==2.0.0 flake8-comprehensions==3.2.2 flake8-debugger==3.2.1 flake8-docstrings==1.5.0 flake8-eradicate==0.3.0 flake8-isort==2.9.1 flake8-plugin-utils==1.3.0 flake8-polyfill==1.0.2 flake8-pytest-style==1.1.1 flake8-quotes==2.1.2 flake8-rst-docstrings==0.0.12 flake8-string-format==0.2.3 future==0.18.2 gitdb==4.0.5 GitPython==3.1.2 grimp==1.2.1 h11==0.9.0 h2==3.2.0 hpack==3.0.0 hstspreload==2020.5.27 httpcore==0.9.1 httpx==0.13.2 hyperframe==5.2.0 idna==2.9 isort==4.3.21 Jinja2==2.11.2 joblib==0.15.1 livereload==2.6.1 loguru==0.4.1 lunr==0.5.8 Markdown==3.2.2 markdown-include==0.5.1 MarkupSafe==1.1.1 mccabe==0.6.1 mkdocs==1.1.2 mkdocs-material==5.2.2 mkdocs-material-extensions==1.0 mkdocstrings==0.11.2 molten==1.0.1 more-itertools==8.3.0 mypy==0.770 mypy-extensions==0.4.3 networkx==2.4 nltk==3.5 nox==2020.5.24 packaging==20.4 pathspec==0.8.0 pbr==5.4.5 pep8-naming==0.9.1 pluggy==0.13.1 public==2019.4.13 py==1.8.1 pycodestyle==2.6.0 pydantic==1.5.1 pydocstyle==5.0.2 pyflakes==2.2.0 Pygments==2.6.1 pymdown-extensions==7.1 pyparsing==2.4.7 pytest==5.4.2 pytest-asyncio==0.12.0 pytest-clarity==0.3.0a0 pytest-cov==2.9.0 pytkdocs==0.4.0 PyYAML==5.3.1 regex==2020.5.14 restructuredtext-lint==1.3.0 rfc3986==1.4.0 self==2019.4.13 six==1.15.0 smmap==3.0.4 sniffio==1.1.0 snowballstemmer==2.0.0 soupsieve==1.9.6 starlette==0.13.2 stevedore==1.32.0 termcolor==1.1.0 testfixtures==6.14.1 tokenize-rt==4.0.0 toml==0.10.1 tornado==6.0.4 tqdm==4.46.0 typed-ast==1.4.1 typing-extensions==3.7.4.2 typing-inspect==0.5.0 virtualenv==20.0.21 wcwidth==0.1.9 wemake-python-styleguide==0.14.0
sobolevn commented 4 years ago

This might be an issue with django models as well:

class Post(models.Model):
    slug = models.CharField(...)

    def save(self, *args, **kwargs):
        self.slug = generate_slug(self)
sobolevn commented 4 years ago

Looks like the only valid solution is to switch this rule off if you are using django, pydantic, etc.