Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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?
=============================
Expand Down
12 changes: 6 additions & 6 deletions astroid/filter_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/unittest_filter_statements.py
Original file line number Diff line number Diff line change
@@ -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