Skip to content

Crash in VariablesChecker._is_only_type_assignment #5162

Closed
@cdce8p

Description

@cdce8p

This change causes a crash when testing Home Assistant.

Exception on node <Name.event_ids l.16 at 0x1052e2230> in file '/Users/marc/Develop/pylint/test5.py'
Traceback (most recent call last):
  File "/Users/marc/Develop/pylint/pylint/utils/ast_walker.py", line 75, in walk
    callback(astroid)
  File "/Users/marc/Develop/pylint/pylint/checkers/variables.py", line 1189, in visit_name
    elif self._is_only_type_assignment(node, name, defstmt):
  File "/Users/marc/Develop/pylint/pylint/checkers/variables.py", line 1560, in _is_only_type_assignment
    for ref_node in node.scope().locals[name][1:]:
KeyError: 'event_ids'

To reproduce

# pylint: disable=undefined-variable

def _purge_filtered_states(session) -> None:
    """Remove filtered states and linked events."""
    state_ids: list[int]
    event_ids: list[int | None]
    state_ids, event_ids = zip(
        *(
            session.query(States.state_id, States.event_id)
            .filter(States.entity_id.in_(excluded_entity_ids))
            .limit(MAX_ROWS_TO_PURGE)
            .all()
        )
    )
    event_ids = [id_ for id_ in event_ids if id_ is not None]

--
Taken from here: homeassistant/components/recorder/purge.py -> _purge_filtered_states

Originally posted by @cdce8p in #5158 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions