-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
C: used-before-assignmentIssues related to 'used-before-assignment' checkIssues related to 'used-before-assignment' checkCrash 💥A bug that makes pylint crashA bug that makes pylint crashNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
C: used-before-assignmentIssues related to 'used-before-assignment' checkIssues related to 'used-before-assignment' checkCrash 💥A bug that makes pylint crashA bug that makes pylint crashNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation