Wemake-python-styleguide: Invoking in flakehell results in exception

Created on 16 Jul 2020  路  8Comments  路  Source: wemake-services/wemake-python-styleguide

Bug report

What's wrong

When invoking flakehell baseline I get following traceback. I can only guess that I have bad annotations somewhere in code, but cannot tell where. Would be happy to provide more info.
Traceback:

Traceback (most recent call last):
  File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/checker.py", line 154, in run
    visitor.run()
  File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/base.py", line 191, in run
    self.visit(self.tree)
  File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
    return route_visit(self, tree)
  File "/Users/ynblagoveshenskiy/.pyenv/versions/3.7.6/lib/python3.7/ast.py", line 271, in visit
    return visitor(node)
  File "/Users/ynblagoveshenskiy/.pyenv/versions/3.7.6/lib/python3.7/ast.py", line 279, in generic_visit
    self.visit(item)
  File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
    return route_visit(self, tree)
  File "/Users/ynblagoveshenskiy/.pyenv/versions/3.7.6/lib/python3.7/ast.py", line 271, in visit
    return visitor(node)
  File "/Users/ynblagoveshenskiy/.pyenv/versions/3.7.6/lib/python3.7/ast.py", line 279, in generic_visit
    self.visit(item)
  File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
    return route_visit(self, tree)
  File "/Users/ynblagoveshenskiy/.pyenv/versions/3.7.6/lib/python3.7/ast.py", line 271, in visit
    return visitor(node)
  File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 34, in visit_any_function
    self._check_function_annotations_complexity(node)
  File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 58, in _check_function_annotations_complexity
    self._check_annotations_complexity(node, annotations)
  File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 67, in _check_annotations_complexity
    complexity = get_annotation_compexity(annotation)
  File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/logic/complexity/annotations.py", line 30, in get_annotation_compexity
    ).body[0].value
IndexError: list index out of range

How is that should be

System information

flake8 information

Contents of flake8 --bug-report:

{
  "dependencies": [],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.7.6",
    "system": "Darwin"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "flake8-bandit",
      "version": "2.1.2"
    },
    {
      "is_local": false,
      "plugin": "flake8-broken-line",
      "version": "0.2.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-bugbear",
      "version": "19.8.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-comprehensions",
      "version": "3.2.3"
    },
    {
      "is_local": false,
      "plugin": "flake8-darglint",
      "version": "1.5.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.3.0"
    },
    {
      "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": "pylint",
      "version": "2.5.3"
    },
    {
      "is_local": false,
      "plugin": "rst-docstrings",
      "version": "0.0.12"
    },
    {
      "is_local": false,
      "plugin": "wemake_python_styleguide",
      "version": "0.14.0"
    }
  ],
  "version": "3.8.3"
}

pip information

Contents of pip freeze:

aadict==0.2.3
aioamqp==0.11.0
aioelasticsearch==0.5.2
aiofiles==0.5.0
aiohttp==3.6.2
aioresponses==0.6.0
apispec==0.39.0
asset==0.6.13
astor==0.8.1
astroid==2.4.2
async-timeout==3.0.1
asyncpg==0.20.1
asynctest==0.13.0
atomicwrites==1.4.0
attrs==19.3.0
bandit==1.6.2
chardet==3.0.4
click==7.1.2
crontab==0.22.6
Cython==0.29.20
darglint==1.5.1
deepdiff==3.3.0
docutils==0.16
elasticsearch==6.8.1
entrypoints==0.3
envparse==0.2.0
eradicate==1.0
expiringdict==1.1.4
flake8==3.8.3
flake8-bandit==2.1.2
flake8-broken-line==0.2.1
flake8-bugbear==19.8.0
flake8-commas==2.0.0
flake8-comprehensions==3.2.3
flake8-debugger==3.2.1
flake8-docstrings==1.5.0
flake8-eradicate==0.3.0
flake8-isort==2.9.1
flake8-polyfill==1.0.2
flake8-quotes==2.1.2
flake8-rst-docstrings==0.0.12
flake8-string-format==0.2.3
flakehell==0.5.0
freezegun==0.3.10
gitdb==4.0.5
GitPython==3.1.7
globre==0.1.5
idna==2.10
importlib-metadata==1.7.0
iniherit==0.3.9
isort==4.3.21
jsonpickle==1.4.1
jsonschema==3.0.2
lazy-object-proxy==1.4.3
lxml==4.5.1
marshmallow==2.18.0
mccabe==0.6.1
more-itertools==8.4.0
multidict==4.7.6
packaging==20.4
pbr==5.4.5
pep8-naming==0.9.1
pluggy==0.13.1
psycopg2-binary==2.8.3
py==1.9.0
pycodestyle==2.6.0
pydantic==1.5.1
pydocstyle==5.0.2
pyflakes==2.2.0
Pygments==2.6.1
pyhocon==0.3.55
PyJWT==1.6.4
pylint==2.5.3
pyparsing==2.4.7
pyrsistent==0.16.0
pytest==5.1.2
pytest-asyncio==0.10.0
python-dateutil==2.6.1
python-slugify==1.2.6
pytz==2019.3
PyYAML==5.3.1
raven==6.10.0
raven-aiohttp==0.7.0
restructuredtext-lint==1.3.1
sanic==0.8.3
Sanic-Cors==0.9.9.post4
Sanic-Plugins-Framework==0.8.2.post1
schematics==2.0.1
six==1.15.0
smmap==3.0.4
snowballstemmer==2.0.0
stevedore==3.1.0
termcolor==1.1.0
testfixtures==6.14.1
text-unidecode==1.3
toml==0.10.1
typed-ast==1.4.1
typer==0.1.1
typing-extensions==3.7.4.2
ujson==1.35
Unidecode==1.1.1
urllib3==1.25.9
uvloop==0.14.0
wait==0.0.3
wcwidth==0.2.5
websockets==5.0.1
wemake-python-styleguide==0.14.0
wrapt==1.12.1
yarl==1.2.6
yoyo-migrations==6.1.0
zipp==3.1.0
bug

All 8 comments

Can you please try to run this command:

find returns -name '*.py' -exec bash -c 'echo {}; flake8 {}' \;

It will print the filename that is checked by flake8. Then, we can track down the incorrect annotation.

Oups, please replace returns with your folder name:

find $YOUR_PROJECT_DIR -name '*.py' -exec bash -c 'echo {}; flake8 {}' \;

Ok, so I ran this command in my project, but this time flake8 didn't crash. I tried this even in fresh virtualenv. I will try later this config on another project, and if there will be exception, I'll run it with find. I believe I should run flakehell instead of flake8, since I am using it?

Yes, possibly it is related. Try again please!

I ran into exception today again on flakehell lint. Traceback:
```File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
return route_visit(self, tree)
File "/Users/ynblagoveshenskiy/.pyenv/versions/3.7.6/lib/python3.7/ast.py", line 271, in visit
return visitor(node)
File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 34, in visit_any_function
self._check_function_annotations_complexity(node)
File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 58, in _check_function_annotations_complexity
self._check_annotations_complexity(node, annotations)
File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 67, in _check_annotations_complexity
complexity = get_annotation_compexity(annotation)
File "/Users/ynblagoveshenskiy/Library/Caches/pypoetry/virtualenvs/complex-sync-CQECTYHO-py3.7/lib/python3.7/site-packages/wemake_python_styleguide/logic/complexity/annotations.py", line 30, in get_annotation_compexity
).body[0].value
IndexError: list index out of range

ERROR:darglint:While getting the names from a caught tuple of exceptions, encountered something other than an ast.Name: Attribute


I tried to run `find . -name '*.py' -exec bash -c 'echo {}; flakehell lint {}' \;`, which resulted in successful check. This happened after I excluded `darglint` error in pyproject.toml like this:

pyproject.toml

[tool.flakehell.plugins]
"flake8-" = ["+", "-DAR101", "-DAR201"]
```

Maybe I can patch my library somewhere to print out file under check?

Should be fixed in #1488. Please, try development version of wemake-python-styleguide. CONTRIBUTING should help with it.

Also, flakehell has --safe argument to suppress exceptions from plugins. It can work as a temporary solution.

Was this page helpful?
0 / 5 - 0 ratings