Skip to content

AttributeError: 'NoneType' object has no attribute 'scope' in variables checker #10105

Closed
@correctmost

Description

@correctmost

Bug description

Pylint crashes on this fuzzed code from pysource-codegen:

@d
class a:
    d: int

import d

Command used

pylint crash.py

Pylint output

Exception on node <Name.d l.1 at 0x77162afcce90> in file 'crash.py'
Traceback (most recent call last):
  File "pylint/pylint/utils/ast_walker.py", line 87, in walk
    callback(astroid)
  File "pylint/pylint/checkers/variables.py", line 1651, in visit_name
    self._undefined_and_used_before_checker(node, stmt)
  File "pylint/pylint/checkers/variables.py", line 1694, in _undefined_and_used_before_checker
    action, nodes_to_consume = self._check_consumer(
                               ^^^^^^^^^^^^^^^^^^^^^
  File "pylint/pylint/checkers/variables.py", line 1942, in _check_consumer
    elif not self._is_builtin(node.name) and self._is_only_type_assignment(
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pylint/pylint/checkers/variables.py", line 2415, in _is_only_type_assignment
    parent_scope = parent.scope()
                   ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'scope'

Expected behavior

No crash

Pylint version

pylint: 55098c7
astroid: cae4388d75
Python 3.12.7

OS / Environment

Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crash 💥A bug that makes pylint crashNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions