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

Setting the identical name between an attribute and a variable causes a fatal error #8754

Closed
xiaxinmeng opened this issue Jun 9, 2023 · 0 comments · Fixed by #8839
Closed
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@xiaxinmeng
Copy link

Setting the identical name between an attribute and a variable causes a fatal error. See the following example.

pylint_example.py

attr = "test"
class T:
    T.attr = attr

The expected behavior:

No fatal error

Pylint output:

>> pylint pylint_example.py
************* Module pylint_example
pylint_example.py:82:0: C0103: Constant name "attr" doesn't conform to UPPER_CASE naming style (invalid-name)
pylint_example.py:83:0: C0115: Missing class docstring (missing-class-docstring)
pylint_example.py:83:0: C0103: Class name "T" doesn't conform to PascalCase naming style (invalid-name)
pylint_example.py:84:4: E0602: Undefined variable 'T' (undefined-variable)
Exception on node <Name.attr l.84 at 0x7f98c1d756d0> in file '/home/xxm/Desktop/pylint_example.py'
Traceback (most recent call last):
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/variables.py", line 1616, in visit_name
    self._undefined_and_used_before_checker(node, stmt)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/variables.py", line 1657, in _undefined_and_used_before_checker
    action, nodes_to_consume = self._check_consumer(
                               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/variables.py", line 1749, in _check_consumer
    found_nodes = current_consumer.get_next_to_consume(node)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/variables.py", line 612, in get_next_to_consume
    if lhs.name == name:  # this name is defined in this very statement
       ^^^^^^^^
AttributeError: 'AssignAttr' object has no attribute 'name'
pylint_example.py:1:0: F0002: /home/xxm/Desktop/pylint_example.py: Fatal error while checking '/home/xxm/Desktop/pylint_example.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/xxm/.cache/pylint/pylint-crash-2023-06-09-15-25-11.txt'. (astroid-error)

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

Test environment:

pylint 3.0.0b1
astroid 3.0.0a5-dev0
Python 3.11.3
Ubuntu 18.04

@jacobtylerwalls jacobtylerwalls added Crash 💥 A bug that makes pylint crash C: used-before-assignment Issues related to 'used-before-assignment' check Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Jun 9, 2023
@jacobtylerwalls jacobtylerwalls added this to the 2.17.5 milestone Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants