From 0e297eb7fb09aef8da6e00427ab1df5d77b8c5d1 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 12 May 2025 22:43:05 +0200 Subject: [PATCH] [fix] Crash when parsing an empty arbitrary expression with ``extract_node`` (#2736) Closes #2734 (cherry picked from commit 59f36e755d04765b2b623c7c51e84509c6b248f6) --- ChangeLog | 2 ++ astroid/builder.py | 1 + tests/test_regrtest.py | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 94d8e482b0..912c9fe203 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 f4be6972b8..22724fa9af 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 f7383d25fb..a7a091b93e 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() == "__()"