Skip to content

Commit c8bd28a

Browse files
[fix] Crash when parsing an empty arbitrary expression with extract_node (pylint-dev#2736) (pylint-dev#2737)
Closes pylint-dev#2734 (cherry picked from commit 59f36e7) Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
1 parent a362368 commit c8bd28a

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ What's New in astroid 3.3.11?
1313
=============================
1414
Release date: TBA
1515

16+
* Fix a crash when parsing an empty arbitrary expression with ``extract_node`` (``extract_node("__()")``).
1617

18+
Closes #2734
1719

1820
What's New in astroid 3.3.10?
1921
=============================

astroid/builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def _extract_expressions(node: nodes.NodeNG) -> Iterator[nodes.NodeNG]:
317317
isinstance(node, nodes.Call)
318318
and isinstance(node.func, nodes.Name)
319319
and node.func.name == _TRANSIENT_FUNCTION
320+
and node.args
320321
):
321322
real_expr = node.args[0]
322323
assert node.parent

tests/test_regrtest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,9 @@ def _get_option(self, option):
497497
)
498498
)
499499
assert node.inferred()[0].value == "mystr"
500+
501+
502+
def test_regression_no_crash_during_build() -> None:
503+
node: nodes.Attribute = extract_node("__()")
504+
assert node.args == []
505+
assert node.as_string() == "__()"

0 commit comments

Comments
 (0)