Skip to content

Stray WPS601 warning on class member reassignment #1926

@agatti

Description

@agatti

What's wrong

Reassigning a value for dataclass member variable from a dataclass member function triggers a stray WPS601 warning.

Here is a code snippet that shows the issue:

from dataclasses import dataclass
from typing import Optional

@dataclass
class DataClass:
    string_value: Optional[str] = None

    def fun(self) -> None:
        self.string_value = self.string_value.strip() if self.string_value else None  # <- WPS601: Found shadowed class attribute: string_value

How it should be

In the code snippet in question there is no shadowing happening, since all instances of string_value are scoped with self.

Flake8 version and plugins

{
"dependencies": [],
"platform": {
"python_implementation": "CPython",
"python_version": "3.8.8",
"system": "Darwin"
},
"plugins": [
{
"is_local": false,
"plugin": "flake8-bandit",
"version": "2.1.2"
},
{
"is_local": false,
"plugin": "flake8-broken-line",
"version": "0.3.0"
},
{
"is_local": false,
"plugin": "flake8-bugbear",
"version": "20.11.1"
},
{
"is_local": false,
"plugin": "flake8-comprehensions",
"version": "3.3.1"
},
{
"is_local": false,
"plugin": "flake8-darglint",
"version": "1.7.0"
},
{
"is_local": false,
"plugin": "flake8-debugger",
"version": "4.0.0"
},
{
"is_local": false,
"plugin": "flake8-docstrings",
"version": "1.5.0, pydocstyle: 5.1.1"
},
{
"is_local": false,
"plugin": "flake8-eradicate",
"version": "1.0.0"
},
{
"is_local": false,
"plugin": "flake8-string-format",
"version": "0.3.0"
},
{
"is_local": false,
"plugin": "flake8_commas",
"version": "2.0.0"
},
{
"is_local": false,
"plugin": "flake8_isort",
"version": "4.0.0"
},
{
"is_local": false,
"plugin": "flake8_quotes",
"version": "3.2.0"
},
{
"is_local": false,
"plugin": "mccabe",
"version": "0.6.1"
},
{
"is_local": false,
"plugin": "naming",
"version": "0.11.1"
},
{
"is_local": false,
"plugin": "pycodestyle",
"version": "2.6.0"
},
{
"is_local": false,
"plugin": "pyflakes",
"version": "2.2.0"
},
{
"is_local": false,
"plugin": "pylint",
"version": "0.0.0"
},
{
"is_local": false,
"plugin": "rst-docstrings",
"version": "0.0.14"
},
{
"is_local": false,
"plugin": "wemake_python_styleguide",
"version": "0.15.2"
}
],
"version": "3.8.4"
}

pip information

pip 20.2.4 from /Users/agatti/Library/Caches/pypoetry/virtualenvs/gls-automator-iJPcva4U-py3.8/lib/python3.8/site-packages/pip (python 3.8)
appdirs @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/68/c7/33/ef0f6af8d1aa906f1a5641762fe5d6f47d565c5a4b3482f1c6fb0f5f20/appdirs-1.4.4-py2.py3-none-any.whl
astor @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/00/68/e3/b2c93c6b1eabbb453b7a288336d64a2bb9f32b6821173440843f97f64b/astor-0.8.1-py2.py3-none-any.whl
attrs @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/b7/28/6f/acdd2c0e759f1cda97abf00db7723a0ffb3a151696d8d96398aea16171/attrs-20.3.0-py2.py3-none-any.whl
bandit @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/a2/02/ff/eaae30b6c44acbb38e05e07e4a685c781ebb46ec87a72eeafbc8ede15b/bandit-1.7.0-py3-none-any.whl
black @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/38/f4/61/550fd050005dc1c64850374a7f98dd941a4633d72e87f147bebf26bdc3/black-20.8b1.tar.gz
click @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/30/bc/bf/e00ffd8f0edf0294942e70e80e42a839bd2649d2c5b864e6389e526d2a/click-7.1.2-py2.py3-none-any.whl
colorama @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/b0/f3/a3/cf94f06cbe1d286a25116cfe54d5a75cb1c4b54d15b2b1b4fc03a7f657/colorama-0.4.4-py2.py3-none-any.whl
darglint @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/d8/74/e4/fdb46c6fd8fac9548f5ae89e42fe0ab76b22887eb67a8baf9d0cd942cd/darglint-1.7.0-py3-none-any.whl
docutils @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/9e/78/f1/81f20d21f3ed304c86fa5394fadbb173e75ad363029a8fefa635dadf2e/docutils-0.16-py2.py3-none-any.whl
entrypoints @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/27/67/42/5ca7438658f76c8700ff6c44ea1cf9dc128cf0862adb7de53d3a35266c/entrypoints-0.3-py2.py3-none-any.whl
eradicate @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/aa/5c/1b/1cc2c911d9f4ca4e28af5d060406e467cd44e84aa2104e58dcb2783545/eradicate-2.0.0.tar.gz
flake8 @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/5c/5b/91/23d9fee55905e042e829a14e2fa56ffd39c81246aba659e2840bab728b/flake8-3.8.4-py2.py3-none-any.whl
flake8-bandit @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/cc/6d/cf/94dc0d884687c0e10baebe95be53977448e1b59d7ad05e41a0f046cd7e/flake8_bandit-2.1.2.tar.gz
flake8-broken-line @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/8f/48/91/0d6bc500782a1a3e000937daf9757ae8a66b6eb6cfb37a205bf8b7f786/flake8_broken_line-0.3.0-py3-none-any.whl
flake8-bugbear @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/ee/34/92/1a1933902453517c848d54696c56cadd58a50e81e7b6822f86a1a8f14a/flake8_bugbear-20.11.1-py36.py37.py38-none-any.whl
flake8-commas @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/b7/aa/76/e620a68b0be70f4132be94bfbfdacb20b16c060174b33dc856818db92d/flake8_commas-2.0.0-py2.py3-none-any.whl
flake8-comprehensions @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/79/68/a1/ad2a93c936991789c7abe3cfaad2061386a4a605875dc6031c7bf68a96/flake8_comprehensions-3.3.1-py3-none-any.whl
flake8-debugger @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/53/fa/32/0169f891a8c8722d66ad761e363416818d8b0bcc7df8ac07903d7e92e7/flake8_debugger-4.0.0-py3-none-any.whl
flake8-docstrings @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/14/46/f1/42800107fb2815121aebf831e269f0af48a45c669a24dbcec60fbbac9f/flake8_docstrings-1.5.0-py2.py3-none-any.whl
flake8-eradicate @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/36/d5/cc/644a05fd3f5223a3cf18d54aa7aa552d16177044159cf71cdb7e277279/flake8_eradicate-1.0.0-py3-none-any.whl
flake8-isort @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/7f/ff/4b/ccb1bf1f070d294477259bb95f68c42dcffe931cbd8e9288d9f8bc2fe9/flake8_isort-4.0.0-py2.py3-none-any.whl
flake8-polyfill @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/37/d4/b9/446f3fe801eea4de2fdff2cd1e0be3fa836d08c04d62174d4ec65113f3/flake8_polyfill-1.0.2-py2.py3-none-any.whl
flake8-quotes @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/12/1f/f0/7623670ff6f28d435847081ac20cd7d4eacb100ab4cd318651dbd2ad1f/flake8-quotes-3.2.0.tar.gz
flake8-rst-docstrings @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/23/55/53/366c0609509a22c9af7a6593751dde0890159781e725e1ce828ada50ce/flake8-rst-docstrings-0.0.14.tar.gz
flake8-string-format @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/fd/52/74/3de7f09d54ed637290f8522dc409ca9af53673b8ddc0d4026f088e4c09/flake8_string_format-0.3.0-py2.py3-none-any.whl
flakehell @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/1e/20/33/c1828805fe5abe2bf39425e410b6dba1a14103fd4b7548af058ca13978/flakehell-0.9.0-py3-none-any.whl
gitdb @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/45/a9/94/d73ced00c6cf302a2e08bedd4f10d3424342b7a8a2fae6e4ccb7276641/gitdb-4.0.5-py3-none-any.whl
GitPython @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/4e/6c/4d/f8f6c8b848d0d99302eaa7a87f7a59e0926307bbce507550c64366d44d/GitPython-3.1.14-py3-none-any.whl
isort @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/c7/65/52/89112b51dedef2d5c6ae731072aace88c4bb499093e551cceec24f2b18/isort-5.7.0-py3-none-any.whl
loguru-mypy @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/0f/c7/77/58fd89282070a92550ea2a5a56db3a57cd8840475f43f9525298839f4b/loguru_mypy-0.0.3-py3-none-any.whl
mccabe @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/37/6e/69/4a33a4d6c80c775b1ee205face2c6e07b762c8602bb0f0d236ebe790c5/mccabe-0.6.1-py2.py3-none-any.whl
mypy @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/a1/d7/a2/283d8c87c1f9fb228c2e9d33e51d9e099e5a66c6e95f516f77a82ce9f0/mypy-0.812-cp38-cp38-macosx_10_9_x86_64.whl
mypy-extensions @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/b6/a0/b0/a5dc9acd6fd12aba308634f21bb7cf0571448f20848797d7ecb327aa12/mypy_extensions-0.4.3-py2.py3-none-any.whl
pastel @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/a3/82/78/1165702c3bd8d7effa892ab5af5542aba9bf145cbaca3c9ec10861de25/pastel-0.2.1-py2.py3-none-any.whl
pathspec @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/5d/98/c8/c7cd4decd7943aa5647824d8553b40e86f4e2ef814ca2a4e73ee708f7f/pathspec-0.8.1-py2.py3-none-any.whl
pbr @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/85/81/cf/9255f6df466921f8291c85ab33df01caeda1916c2745a5071ce06a963f/pbr-5.5.1-py2.py3-none-any.whl
pendulum @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/3d/b6/88/afe8e7e932d9131ebd9fe995f5fea4fd77d503f343f9b7da61290b17f8/pendulum-2.1.2-cp38-cp38-macosx_10_15_x86_64.whl
pep8-naming @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/e7/c8/00/b145306a40eba2961774c78d56e8fb9b09c08e44af6fd83642c5114bba/pep8_naming-0.11.1-py2.py3-none-any.whl
poethepoet @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/ea/33/99/b9c2234550c735d46af601efdeb043d629025a20eeb2d41d50198eeb28/poethepoet-0.10.0-py3-none-any.whl
pycodestyle @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/01/f4/cf/c7e34cb76e03e95d9eff28af16fe09ee8edd01cc985fc2b88453b6d311/pycodestyle-2.6.0-py2.py3-none-any.whl
pydocstyle @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/a4/ef/58/498033174cb8c68875036ec5d8a3d9d2e169c51bec9d35866bd62ff5ac/pydocstyle-5.1.1-py3-none-any.whl
pyflakes @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/da/83/11/1e9a80c39638c6967e9b1117b17d8ec5f723ddd0a88251cc08dc0807b0/pyflakes-2.2.0-py2.py3-none-any.whl
Pygments @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/d8/89/8d/dd9d739214940ed315c7a6aa2fc949a9ed6257976b13c0e7d40e684012/Pygments-2.8.0-py3-none-any.whl
python-dateutil @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/1e/2c/dc/0e811c2299b40168ee1da03bc13c11762ce9fa96eb867ad22280db11fc/python_dateutil-2.8.1-py2.py3-none-any.whl
pytzdata @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/c6/0d/bc/7911b53cb0aa9ce069ef59cf2553c999a5dec47954f2d3c69bcb2dd621/pytzdata-2020.1-py2.py3-none-any.whl
PyYAML @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/99/c6/60/2baceb8eb743927ffda4f0184e9aea5339ca72c9a463509feeeb0d1668/PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl
regex @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/e0/83/12/fa2b876292757ada6c8e31db47fe4a424e2527810123e5ed316006f6d3/regex-2020.11.13-cp38-cp38-macosx_10_9_x86_64.whl
restructuredtext-lint @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/7b/45/5c/94b65fa89812c0d8701b8af07cdd43b8a91f5e8d84776984b12942b4cc/restructuredtext_lint-1.3.2.tar.gz
six @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/be/98/c7/69fe6fea7a59659af1c6260899226129565330b1e07c9c5b3769be76bf/six-1.15.0-py2.py3-none-any.whl
smmap @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/ab/27/f3/6ab65f7970ca4dbc0d01a73d5a79abe597252970bf3abc442a7084a6f5/smmap-3.0.5-py2.py3-none-any.whl
snowballstemmer @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/a6/21/11/58b79c57cfc922455998165c2ecc503603be058fe178af058936deaf1f/snowballstemmer-2.1.0-py2.py3-none-any.whl
stevedore @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/df/1c/87/ee139e37999b53501924b31a04b30301f789c2944af24daea1ada94ceb/stevedore-3.3.0-py3-none-any.whl
testfixtures @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/33/ef/82/2cdf5deff816074815a062ea94bc53083040ae5ca90178494e082a6cc0/testfixtures-6.17.1-py2.py3-none-any.whl
toml @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/9f/8c/c3/7b4f6778d60f3c9fa11f8fd0e48243bbad25a04975e0a01006b6350594/toml-0.10.2-py2.py3-none-any.whl
tomlkit @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/db/c3/df/baf014ce3b04caffe7ac34bde699f5be82c4acbaf43f49db1ce681a500/tomlkit-0.7.0-py2.py3-none-any.whl
typed-ast @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/e5/b5/79/23ee82b09fc7da4721300ac1169f9245ef341c44d7abc2564330a69214/typed_ast-1.4.2-cp38-cp38-macosx_10_9_x86_64.whl
typing-extensions @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/ac/8f/3a/97dfae6ca13a6e156f19a5e8aa95fc250129d7e5e6cd0f7c76a1d45b4f/typing_extensions-3.7.4.3-py3-none-any.whl
urllib3 @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/a9/fc/7b/ab7ab6ea0d0cbf7347c6de7a3ab67af2f715357ebb539bdf464671b640/urllib3-1.26.3-py2.py3-none-any.whl
wemake-python-styleguide @ file:///Users/agatti/Library/Caches/pypoetry/artifacts/80/1a/f6/8845722373a0ecf2fad93ef5c639738d34e0c3bec1b3afd323226de1b3/wemake_python_styleguide-0.15.2-py3-none-any.whl

OS information

Darwin rotifer.local 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions