Skip to content

AttributeError: 'NoneType' object has no attribute 'as_string' in code_style checker #10707

@correctmost

Description

@correctmost

Bug description

Pylint crashes on this fuzzed code:

i: int
if i:
    pass

Configuration

Command used

pylint --enable-all-extensions crash.py

Pylint output

Traceback (most recent call last):
  File "pylint/pylint/utils/ast_walker.py", line 87, in walk
    callback(astroid)
    ~~~~~~~~^^^^^^^^^
  File "pylint/pylint/extensions/code_style.py", line 166, in visit_if
    self._check_consider_using_assignment_expr(node)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "pylint/pylint/extensions/code_style.py", line 286, in _check_consider_using_assignment_expr
    f"({node_name.name} := {prev_sibling.value.as_string()})",
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'as_string'

Expected behavior

No crash

Pylint version

pylint: bb9df16
astroid: pylint-dev/astroid@bd6e3049db110
Python 3.13.7

OS / Environment

Arch Linux

Additional dependencies

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions