Skip to content

Crash 'AssignAttr' object has no attribute 'name' when not TYPE_CHECKING #5111

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

Closed
JacobHayes opened this issue Oct 3, 2021 · 1 comment · Fixed by #5118
Closed

Crash 'AssignAttr' object has no attribute 'name' when not TYPE_CHECKING #5111

JacobHayes opened this issue Oct 3, 2021 · 1 comment · Fixed by #5118
Assignees
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash
Milestone

Comments

@JacobHayes
Copy link

JacobHayes commented Oct 3, 2021

Bug description

This bug arises under somewhat odd conditions. My original code was trying to patch around python/cpython#28714 with:

from graphlib import TopologicalSorter
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    print("do some stuff")
else:
    from types import GenericAlias

    TopologicalSorter.__class_getitem__ = classmethod(GenericAlias)

I've tried to reduce as much as possible and the key parts seem to be:

  • in the else block after if TYPE_CHECKING (if not TYPE_CHECKING doesn't seem to trigger)
  • when referencing an import within the block (doesn't have to be GenericAlias and moving import to top fixes)
  • when assigning an attribute (doesn't have to be TopologicalSorter nor __class_getitem__)

Configuration

No response

Command used

pylint min_repro.py

Pylint output

************* Module min_repro
min_repro.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Exception on node <Name.GenericAlias l.9 at 0x10dae0580> in file '/private/tmp/min_repro.py'
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    callback(astroid)
  File "/usr/local/lib/python3.9/site-packages/pylint/checkers/variables.py", line 1106, in visit_name
    ) = self._is_variable_violation(
  File "/usr/local/lib/python3.9/site-packages/pylint/checkers/variables.py", line 1533, in _is_variable_violation
    defined_in_or_else = any(
  File "/usr/local/lib/python3.9/site-packages/pylint/checkers/variables.py", line 1534, in <genexpr>
    target.name == name for target in definition.targets
AttributeError: 'AssignAttr' object has no attribute 'name'
min_repro.py:1:0: F0001: Fatal error while checking 'min_repro.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/Users/jacobhayes/Library/Caches/pylint/pylint-crash-2021-10-03-18.txt'. (fatal)

------------------------------------------------------------------
Your code has been rated at 8.33/10 (previous run: 8.33/10, +0.00)

Expected behavior

************* Module min_repro
min_repro.py:1:0: C0114: Missing module docstring (missing-module-docstring)

------------------------------------------------------------------
Your code has been rated at 8.33/10 (previous run: 8.33/10, +0.00)

Pylint version

pylint 2.11.1
astroid 2.8.0
Python 3.9.7 (default, Sep  3 2021, 12:37:55)
[Clang 12.0.5 (clang-1205.0.22.9)]

OS / Environment

macOS

Additional dependencies

No response

@JacobHayes JacobHayes added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 3, 2021
@cdce8p cdce8p added Crash 💥 A bug that makes pylint crash and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 4, 2021
@cdce8p cdce8p self-assigned this Oct 4, 2021
@cdce8p
Copy link
Member

cdce8p commented Oct 5, 2021

Thanks for the report! The fix will be included in the next release.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.11.2 milestone Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants