diff --git a/ChangeLog b/ChangeLog index 0eec5468c1..ec4a9860a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,10 @@ Release date: TBA * Fix ``col_offset`` attribute for nodes involving ``with`` on ``PyPy``. +* Fixed a crash when ``_filter_stmts`` encounters an ``EmptyNode``. + + Closes PyCQA/pylint#6438 + What's New in astroid 2.11.3? ============================= diff --git a/astroid/filter_statements.py b/astroid/filter_statements.py index 528e0bef5a..86a63f3a09 100644 --- a/astroid/filter_statements.py +++ b/astroid/filter_statements.py @@ -112,15 +112,15 @@ def _filter_stmts(base_node: nodes.NodeNG, stmts, frame, offset): # Fixes issue #375 if mystmt is stmt and _is_from_decorator(base_node): continue - assert hasattr(node, "assign_type"), ( - node, - node.scope(), - node.scope().locals, - ) - assign_type = node.assign_type() if node.has_base(base_node): break + if isinstance(node, nodes.EmptyNode): + # EmptyNode does not have assign_type(), so just add it and move on + _stmts.append(node) + continue + + assign_type = node.assign_type() _stmts, done = assign_type._get_filtered_stmts(base_node, node, _stmts, mystmt) if done: break diff --git a/tests/unittest_filter_statements.py b/tests/unittest_filter_statements.py new file mode 100644 index 0000000000..9377b1e230 --- /dev/null +++ b/tests/unittest_filter_statements.py @@ -0,0 +1,17 @@ +# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html +# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE +# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt + +from astroid.builder import extract_node +from astroid.filter_statements import _filter_stmts +from astroid.nodes import EmptyNode + + +def test_empty_node() -> None: + enum_mod = extract_node("import enum") + empty = EmptyNode(parent=enum_mod) + empty.is_statement = True + filtered_statements = _filter_stmts( + empty, [empty.statement(future=True)], empty.frame(future=True), 0 + ) + assert filtered_statements[0] is empty