diff --git a/ChangeLog b/ChangeLog index 94d8e482b..912c9fe20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,9 @@ What's New in astroid 3.3.11? ============================= Release date: TBA +* Fix a crash when parsing an empty arbitrary expression with ``extract_node`` (``extract_node("__()")``). + Closes #2734 What's New in astroid 3.3.10? ============================= diff --git a/astroid/builder.py b/astroid/builder.py index f4be6972b..22724fa9a 100644 --- a/astroid/builder.py +++ b/astroid/builder.py @@ -317,6 +317,7 @@ def _extract_expressions(node: nodes.NodeNG) -> Iterator[nodes.NodeNG]: isinstance(node, nodes.Call) and isinstance(node.func, nodes.Name) and node.func.name == _TRANSIENT_FUNCTION + and node.args ): real_expr = node.args[0] assert node.parent diff --git a/tests/test_regrtest.py b/tests/test_regrtest.py index f7383d25f..a7a091b93 100644 --- a/tests/test_regrtest.py +++ b/tests/test_regrtest.py @@ -497,3 +497,9 @@ def _get_option(self, option): ) ) assert node.inferred()[0].value == "mystr" + + +def test_regression_no_crash_during_build() -> None: + node: nodes.Attribute = extract_node("__()") + assert node.args == [] + assert node.as_string() == "__()"