question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Annotation raises `object has no attribute 'value'` on python 3.9

See original GitHub issue

Bug report

What’s wrong

When I run flake8 with wemake-python-styleguide I received an exception about annotation check.

/Users/DBoger/PycharmProjects/project/.venv/bin/python -m flake8 project
Traceback (most recent call last):
  File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/checker.py", line 154, in run
    visitor.run()
  File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 191, in run
    self.visit(self.tree)
  File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
    return route_visit(self, tree)
  File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
    return getattr(
  File "/Users/DBoger/.pyenv/versions/3.9.0b5/lib/python3.9/ast.py", line 408, in generic_visit
    self.visit(item)
  File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/base.py", line 186, in visit
    return route_visit(self, tree)
  File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/compat/routing.py", line 36, in route_visit
    return getattr(
  File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 34, in visit_any_function
    self._check_function_annotations_complexity(node)
  File "/Users/DBoger/PycharmProjects/project/.venv/lib/python3.9/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/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/visitors/ast/complexity/annotations.py", line 67, in _check_annotations_complexity
    complexity = get_annotation_compexity(annotation)
  File "/Users/DBoger/PycharmProjects/sellerly-profile/.venv/lib/python3.9/site-packages/wemake_python_styleguide/logic/complexity/annotations.py", line 36, in get_annotation_compexity
    annotation_node.slice.value,  # type: ignore
AttributeError: 'Tuple' object has no attribute 'value'

For me, It looks like ast.Subscript.slice doesn’t have .value on python3.9

How is that should be

System information

flake8 information

Contents of flake8 --bug-report:

{
  "dependencies": [],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.9.0",
    "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.5"
    },
    {
      "is_local": false,
      "plugin": "flake8-debugger",
      "version": "3.2.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-docstrings",
      "version": "1.5.0, pydocstyle: 5.1.1"
    },
    {
      "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": "3.0.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.1"
    }
  ],
  "version": "3.8.4"
}

pip information

Contents of pip freeze:

❯ poetry show
aiocache                 0.11.1    multi backend asyncio cache
astor                    0.8.1     Read/rewrite/write Python ASTs
attrs                    20.2.0    Classes Without Boilerplate
bandit                   1.6.2     Security oriented static analyser for python code.
certifi                  2020.6.20 Python package for providing Mozilla's CA Bundle.
cffi                     1.14.3    Foreign Function Interface for Python calling C code.
click                    7.1.2     Composable command line interface toolkit
cryptography             3.1.1     cryptography is a package which provides cryptographic recipes and primitiv...
darglint                 1.5.5     A utility for ensuring Google-style docstrings stay up to date with the sou...
dnspython                2.0.0     DNS toolkit
docutils                 0.16      Docutils -- Python Documentation Utilities
ecdsa                    0.14.1    ECDSA cryptographic signature library (pure python)
email-validator          1.1.1     A robust email syntax and deliverability validation library for Python 2.x/...
eradicate                1.0       Removes commented-out code.
fastapi                  0.61.1    FastAPI framework, high performance, easy to learn, fast to code, ready for...
flake8                   3.8.4     the modular source code checker: pep8 pyflakes and co
flake8-bandit            2.1.2     Automated security testing with bandit and flake8.
flake8-broken-line       0.2.1     Flake8 plugin to forbid backslashes for line breaks
flake8-bugbear           19.8.0    A plugin for flake8 finding likely bugs and design problems in your program...
flake8-commas            2.0.0     Flake8 lint for trailing commas.
flake8-comprehensions    3.2.3     A flake8 plugin to help you write better list/set/dict comprehensions.
flake8-debugger          3.2.1     ipdb/pdb statement checker plugin for flake8
flake8-docstrings        1.5.0     Extension for flake8 which uses pydocstyle to check docstrings
flake8-eradicate         0.3.0     Flake8 plugin to find commented out code
flake8-isort             3.0.1     flake8 plugin that integrates isort .
flake8-polyfill          1.0.2     Polyfill package for Flake8 plugins
flake8-quotes            2.1.2     Flake8 lint for quotes.
flake8-rst-docstrings    0.0.12    Python docstring reStructuredText (RST) validator
flake8-string-format     0.2.3     string format checker, plugin for flake8
gitdb                    4.0.5     Git Object Database
gitpython                3.1.9     Python Git Library
h11                      0.9.0     A pure-Python, bring-your-own-I/O implementation of HTTP/1.1
httpcore                 0.11.1    A minimal low-level HTTP client.
httpx                    0.15.5    The next generation HTTP client.
idna                     2.10      Internationalized Domain Names in Applications (IDNA)
isort                    4.3.21    A Python utility / library to sort Python imports.
mccabe                   0.6.1     McCabe checker, plugin for flake8
mypy                     0.782     Optional static typing for Python
mypy-extensions          0.4.3     Experimental type system extensions for programs checked with the mypy type...
pbr                      5.5.0     Python Build Reasonableness
pep8-naming              0.9.1     Check PEP-8 naming conventions, plugin for flake8
pyasn1                   0.4.8     ASN.1 types and codecs
pycodestyle              2.6.0     Python style guide checker
pycparser                2.20      C parser in Python
pydantic                 1.6.1     Data validation and settings management using python 3.6 type hinting
pydocstyle               5.1.1     Python docstring style checker
pyflakes                 2.2.0     passive checker of Python programs
pygments                 2.7.1     Pygments is a syntax highlighting package written in Python.
python-jose              3.2.0     JOSE implementation in Python
python-multipart         0.0.5     A streaming multipart parser for Python
pyyaml                   5.3.1     YAML parser and emitter for Python
restructuredtext-lint    1.3.1     reStructuredText linter
rfc3986                  1.4.0     Validating URI References per RFC 3986
rsa                      4.6       Pure-Python RSA implementation
six                      1.15.0    Python 2 and 3 compatibility utilities
smmap                    3.0.4     A pure Python implementation of a sliding window memory map manager
sniffio                  1.1.0     Sniff out which async library your code is running under
snowballstemmer          2.0.0     This package provides 26 stemmers for 25 languages generated from Snowball ...
starlette                0.13.6    The little ASGI library that shines.
stevedore                3.2.2     Manage dynamic plugins for Python applications
testfixtures             6.14.2    A collection of helpers and mock objects for unit tests and doc tests.
toml                     0.10.1    Python Library for Tom's Obvious, Minimal Language
typed-ast                1.4.1     a fork of Python 2 and 3 ast modules with type comment support
typing-extensions        3.7.4.3   Backported and Experimental Type Hints for Python 3.5+
uvicorn                  0.12.1    The lightning-fast ASGI server.
wemake-python-styleguide 0.14.1    The strictest and most opinionated python linter ever

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tirkarthicommented, Oct 13, 2020

I have created #1666 to fix this. The tests will fail in Python 3.9 in python -m pytest tests/test_visitors/test_ast/test_complexity . Unfortunately, python 3.9 cannot be tested until 3.9.1 is released with the parser fix. I am running on a low end machine so some of the tests still report memory error. I guess there are couple of more issues to fix until 3.9 is properly supported.

0reactions
sobolevncommented, Oct 13, 2020

Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Annotations Best Practices — Python 3.11.1 documentation
Since the class may or may not have annotations defined, best practice is to call the get method on the class dict. To...
Read more >
Python variable and function annotation raises AttributeError
Can anyone explain why the annotation datetime.datetime raises only an AttributeError for the function return value and the time variable, but ...
Read more >
Common issues and solutions - mypy 0.991 documentation
This section has examples of cases when you need to update your code to use static typing, and ideas for working around issues...
Read more >
Mypy Documentation - Read the Docs
because "greeting" does not have type annotations. ... In Python 3.9 and later, built-in collection type objects support indexing:.
Read more >
Exceptions and common tracebacks - Plone Documentation
AttributeError: 'module' object has no attribute 'HTTPSConnection'¶. Python has not been compiled with HTTPS support. Try installing your Python, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found