Closed
Description
If a 'nonlocal' variable are assigned with a variable outside a function, Pylint fails to handle it. See the following example.
example.py:
nonlocal X
X = whatever
The expected output:
There is no a fatal error.
The actual output:
>> pylint example.py
************* Module pylint_example
Desktop/pylint_example.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Desktop/pylint_example.py:3:0: E0117: nonlocal name X found without binding (nonlocal-without-binding)
Exception on node <Assign l.4 at 0x7fdb12c04a90> 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 2043, in visit_assign
self._check_self_cls_assign(node)
File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/variables.py", line 2920, in _check_self_cls_assign
scope = node.scope().parent.scope()
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'scope'
Desktop/empirical_type_checker/bug_report/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-06-15-56-31.txt'. (astroid-error)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
Test Environment:
Ubuntu 18.04,
CPython 3.11.3
Pylint: 3.0.0b1
astroid 3.0.0a3