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

AttributeError: 'Subscript' object has no attribute 'name' #4439

Closed
MrTrick opened this issue May 4, 2021 · 5 comments · Fixed by #4730
Closed

AttributeError: 'Subscript' object has no attribute 'name' #4439

MrTrick opened this issue May 4, 2021 · 5 comments · Fixed by #4730
Assignees
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@MrTrick
Copy link

MrTrick commented May 4, 2021

Seems distinct from #2250
Maybe a regression, or another edge case?

Steps to reproduce

Given a file a.py:

from attr import attrs, attrib
from typing import Optional

@attrs()
class User:
    name: str = attrib()
    age: int = attrib()
    occupation = Optional[str] = attrib(default=None)

Where a typo was made in the last line - first = should be :.

Current behavior

Pylint crashes if executed on the file, or on any file that imports it.

# pylint a.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 1041, in get_ast
    return MANAGER.ast_from_file(filepath, modname, source=True)
  File "/usr/local/lib/python3.7/site-packages/astroid/manager.py", line 98, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 142, in file_build
    return self._post_build(module, encoding)
  File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 166, in _post_build
    module = self._manager.visit_transforms(module)
  File "/usr/local/lib/python3.7/site-packages/astroid/manager.py", line 75, in visit_transforms
    return self._transform.visit(node)
  File "/usr/local/lib/python3.7/site-packages/astroid/transforms.py", line 90, in visit
    module.body = [self._visit(child) for child in module.body]
  File "/usr/local/lib/python3.7/site-packages/astroid/transforms.py", line 90, in <listcomp>
    module.body = [self._visit(child) for child in module.body]
  File "/usr/local/lib/python3.7/site-packages/astroid/transforms.py", line 58, in _visit
    return self._transform(node)
  File "/usr/local/lib/python3.7/site-packages/astroid/transforms.py", line 41, in _transform
    ret = transform_func(node)
  File "/usr/local/lib/python3.7/site-packages/astroid/brain/brain_attrs.py", line 58, in attr_attributes_transform
    node.locals[target.name] = [rhs_node]
AttributeError: 'Subscript' object has no attribute 'name'
************* Module a
a.py:1:0: F0002: <class 'AttributeError'>: 'Subscript' object has no attribute 'name' (astroid-error)

Additionally: If you run pylint b.py where b.py is:

from a import User

The error message does not mention a.py at all:

Exception on node <ImportFrom l.3 at 0x7fe42b22d490> in file '/tmp/b.py'
Traceback (most recent call last):
<SNIP>
AttributeError: 'Subscript' object has no attribute 'name'

Expected behavior

Should catch and report the problem, not crash. Perhaps:

************* Module a
a.py:8:13: E1137: 'Optional' does not support item assignment (unsupported-assignment-operation)

pylint --version output

Result of pylint --version output:

# pylint --version
pylint 3.0.0a3
astroid 2.5.6
Python 3.7.7 (default, Apr 16 2020, 18:55:06)
[GCC 8.3.0]

Additional dependencies

attrs==19.3.0
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Blocker 🙅 Blocks the next release labels May 4, 2021
@Pierre-Sassoulas
Copy link
Member

Look like we're affected in our own merge request (#4422)

@cdce8p cdce8p removed the Blocker 🙅 Blocks the next release label May 6, 2021
@FrankyBoy
Copy link

Same error, different location:

Traceback (most recent call last):
  File "/path/to/venv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/lint/run.py", line 384, in __init__
    linter.check(args)
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/lint/pylinter.py", line 973, in check
    self._check_files(
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/lint/pylinter.py", line 1007, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/lint/pylinter.py", line 1033, in _check_file
    check_astroid_module(ast_node)
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/lint/pylinter.py", line 1170, in check_astroid_module
    retval = self._check_astroid_module(
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/lint/pylinter.py", line 1215, in _check_astroid_module
    walker.walk(ast_node)
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/utils/ast_walker.py", line 79, in walk
    callback(astroid)
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/checkers/classes.py", line 903, in leave_classdef
    self._check_unused_private_attributes(node)
  File "/path/to/venv/lib64/python3.9/site-packages/pylint/checkers/classes.py", line 966, in _check_unused_private_attributes
    and attribute.expr.name == assign_attr.expr.name
AttributeError: 'Subscript' object has no attribute 'name'

pylint --version:
pylint 2.9.3
astroid 2.6.2
Python 3.9.5 (default, May 05 2021, 15:23:13) [GCC]

@Pierre-Sassoulas
Copy link
Member

@FrankyBoy could you open another issue and provide the code or a snippet that is making pylint crash, please ?

@Pierre-Sassoulas
Copy link
Member

Sorry I thought this issue was closed, no need to create a new one.

@FrankyBoy
Copy link

Heh, forgot to exclude the venv from my scan, and this failure actually comes from some library code ... it's pyparsing (venv/lib/python3.9/site-packages/pyparsing.py). Installed version is 2.4.7. Sadly this is some minified file so I can't really give any more concrete pointers right now :/

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.5 milestone Jul 13, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 20, 2021
@Pierre-Sassoulas Pierre-Sassoulas self-assigned this Jul 20, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Jul 20, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 21, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants