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

WPS601 in classes derived from Django models #1197

Closed
RandyRomero opened this issue Feb 27, 2020 · 1 comment
Closed

WPS601 in classes derived from Django models #1197

RandyRomero opened this issue Feb 27, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@RandyRomero
Copy link

Bug report

What's wrong

Django 3.0.3
I have a model derived from Django standard model. Checking this code gives me WPS601 Found shadowed class attribute.

class MyModel(models.Model):   
    foo = models.TextField()   # setting a class attribute
    def my_method(self):
        self.foo = "new value"  # updating aforementioned class attribute 

How is that should be

The linter alarms about WPS601 because I didn't declare self.foo within dunder init method, it's understandable. But Django docs discourage programmers to reimplement dunder init within classes derived from Django models. So imo within classes derived from Django models we shouldn't get WPS601 error.

System information

flake8 information

{
"dependencies": [
{
"dependency": "entrypoints",
"version": "0.3"
}
],
"platform": {
"python_implementation": "CPython",
"python_version": "3.7.6",
"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.2.2"
},
{
"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.2"
},
{
"is_local": false,
"plugin": "flake8-eradicate",
"version": "0.2.4"
},
{
"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": "4.1.0"
},
{
"is_local": false,
"plugin": "rst-docstrings",
"version": "0.0.12"
},
{
"is_local": false,
"plugin": "wemake-python-styleguide",
"version": "0.13.4"
}
],
"version": "3.7.9"
}

pip information

add-trailing-comma 1.5.0
appdirs 1.4.3
asgiref 3.2.3
astor 0.8.1
astroid 2.3.3
attrs 19.3.0
bandit 1.6.2
black 19.10b0
cachetools 4.0.0
certifi 2019.11.28
cffi 1.14.0
chardet 3.0.4
Click 7.0
cognitive-complexity 0.0.4
colorama 0.4.1
coreapi 2.3.3
coreschema 0.0.4
coverage 5.0.3
cryptography 2.8
darglint 1.1.2
Django 3.0.2
django-debug-toolbar 2.1
django-filter 2.2.0
django-ipware 2.1.0
django-prometheus 2.0.0
django-structlog 1.3.5
djangorestframework 3.11.0
dnspython 1.16.0
docutils 0.16
dparse 0.4.1
drf-extensions 0.6.0
drf-yasg 1.17.0
entrypoints 0.3
eradicate 1.0
eventlet 0.25.1
flake8 3.7.9
flake8-annotations-complexity 0.0.2
flake8-bandit 2.1.2
flake8-blind-except 0.1.1
flake8-broken-line 0.1.1
flake8-bugbear 19.8.0
flake8-builtins 1.4.2
flake8-coding 1.3.2
flake8-commas 2.0.0
flake8-comprehensions 3.2.2
flake8-debugger 3.2.1
flake8-docstrings 1.5.0
flake8-eradicate 0.2.4
flake8-executable 2.0.3
flake8-isort 2.8.0
flake8-logging-format 0.6.0
flake8-pep3101 1.3.0
flake8-plugin-utils 1.0.0
flake8-polyfill 1.0.2
flake8-print 3.1.4
flake8-pytest-style 0.1.3
flake8-quotes 2.1.1
flake8-rst-docstrings 0.0.12
flake8-string-format 0.2.3
flakehell 0.3.3
future 0.18.2
gitdb2 2.0.6
GitPython 3.0.5
greenlet 0.4.15
gunicorn 20.0.4
hrm 0.1.0 /Users/mikheevaia/pik_dev/hrm
idna 2.8
importlib-metadata 1.5.0
inflection 0.3.1
isort 4.3.21
itypes 1.1.0
Jinja2 2.11.0
lazy-object-proxy 1.4.3
mando 0.6.4
MarkupSafe 1.1.1
matchlib 0.2.1
mccabe 0.6.1
mimesis 3.3.0
model-bakery 1.1.0
monotonic 1.5
more-itertools 8.2.0
multidict 4.7.4
mypy 0.761
mypy-extensions 0.4.3
packaging 20.1
pathspec 0.7.0
pbr 5.4.4
pep8-naming 0.9.1
phonenumbers 8.11.2
pika 1.1.0
pip 19.2.3
pluggy 0.13.1
prometheus-client 0.7.1
psycopg2-binary 2.8.4
py 1.8.1
pycodestyle 2.5.0
pycparser 2.19
pydocstyle 5.0.2
pyflakes 2.1.1
Pygments 2.5.2
PyJWT 1.7.1
pylint 2.4.4
pyOpenSSL 19.1.0
pyparsing 2.4.6
pytest 5.3.5
pytest-cov 2.8.1
pytest-django 3.8.0
pytest-mock 2.0.0
pytz 2019.3
PyYAML 5.3
radon 4.1.0
regex 2020.1.8
requests 2.22.0
restructuredtext-lint 1.3.0
ruamel.yaml 0.16.7
ruamel.yaml.clib 0.2.0
safety 1.8.5
sentry-sdk 0.14.1
setuptools 41.2.0
six 1.14.0
smmap2 2.0.5
snowballstemmer 2.0.0
sqlparse 0.3.0
stevedore 1.31.0
structlog 20.1.0
termcolor 1.1.0
testfixtures 6.11.0
tokenize-rt 3.2.0
toml 0.10.0
typed-ast 1.4.1
typing-extensions 3.7.4.1
ujson 1.35
uritemplate 3.0.1
urllib3 1.25.8
wcwidth 0.1.8
wemake-python-styleguide 0.13.4
wrapt 1.11.2
xenon 0.7.0
yarl 1.4.2
zipp 2.1.0

@RandyRomero RandyRomero added the bug Something isn't working label Feb 27, 2020
@sobolevn
Copy link
Member

Thanks a lot for the report!

This case is understandable. People do want and will override Django model class / instance fields. But, there's nothing we can do from our side. Because we cannot tell if that's a Django model or not.

So, the solution is to use per-file-ignores and just ignore WPS601 for all your models.py where you do use this. Or if this is a one time problem: use # noqa: WPS601

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

2 participants