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

[2.7.3 regression] AttributeError: 'Attribute' object has no attribute 'name' #4264

Closed
webknjaz opened this issue Mar 29, 2021 · 1 comment · Fixed by #4266
Closed

[2.7.3 regression] AttributeError: 'Attribute' object has no attribute 'name' #4264

webknjaz opened this issue Mar 29, 2021 · 1 comment · Fixed by #4266
Milestone

Comments

@webknjaz
Copy link
Contributor

Steps to reproduce

I don't fully understand what triggers it but here's a traceback:

👉 Traceback 👈
"""
Traceback (most recent call last):
  File "~/.pyenv/versions/3.9.0/lib/python3.9/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/lint/parallel.py", line 69, in _worker_check_single_file
    _worker_linter.check_single_file(name, filepath, modname)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 895, in check_single_file
    self._check_file(
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 936, in _check_file
    check_astroid_module(ast_node)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1070, in check_astroid_module
    retval = self._check_astroid_module(
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1115, in _check_astroid_module
    walker.walk(ast_node)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/checkers/base.py", line 1998, in visit_assignname
    or utils.is_class_var(node)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/checkers/utils.py", line 1466, in is_class_var
    and node.parent.annotation.value.name == "ClassVar"
AttributeError: 'Attribute' object has no attribute 'name'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "~/.pyenv/versions/3.9.0/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "~/.pyenv/versions/3.9.0/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/__main__.py", line 9, in <module>
    pylint.run_pylint()
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/lint/run.py", line 358, in __init__
    linter.check(args)
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 880, in check
    check_parallel(
  File "~/src/github/sanitizers/octomachinery/.tox/pre-commit-ci/lib/python3.9/site-packages/pylint/lint/parallel.py", line 138, in check_parallel
    for (
  File "~/.pyenv/versions/3.9.0/lib/python3.9/multiprocessing/pool.py", line 870, in next
    raise value
AttributeError: 'Attribute' object has no attribute 'name'

I've confirmed that downgrading to v2.7.2 does fix this problem.

Current behavior

Log: https://github.com/sanitizers/octomachinery/runs/2222690514?check_suite_focus=true#step:7:91

Expected behavior

no traceback

env

pylint v2.7.3, executed via the pre-commit.com tool (which seems irrelevant, though)
Python 3.9 (locally) and 3.8 (in CI)

STR

(sorry, I don't have time to distil a small reproducer but this is better than nothing)

  1. clone https://github.com/sanitizers/octomachinery
  2. pip install tox
  3. vim tox.ini — bump pylint version to 2.7.3
  4. tox -e pre-commit -- pylint — this should show the traceback
webknjaz referenced this issue in sanitizers/octomachinery Mar 29, 2021
NOTE: v2.7.3 causes a traceback.
@cdce8p
Copy link
Member

cdce8p commented Mar 30, 2021

Thanks for the report! I've opened #4266 to address it.

If you don't want to wait for the next release, you could try the this workaround. The error is raised by class variables that have a subscript annotation and use attribute access.

import typing

class MyClass:
    var: typing.List[int]  # error (currently)

If you instead use

from typing import List

class MyClass:
    var: List[int]

it will work.

You can use this regex to find most / all locations:

^ {4}\w+: \w+\..+\[\w.*\]

I did a quick scan of your repository. The issue seems to be with

octomachinery/app/routing/webhooks_dispatcher.py
octomachinery/github/models/__init__.py

skirpichev added a commit to diofant/diofant that referenced this issue Mar 30, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.7.4 milestone Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants