File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,10 @@ What's New in astroid 3.3.11?
37
37
=============================
38
38
Release date: TBA
39
39
40
+ * Fix a crash when the root of a node is not a module but is unknown.
41
+
42
+ Closes #2672
43
+
40
44
* Fix a crash when parsing an empty arbitrary expression with ``extract_node`` (``extract_node("__()")``).
41
45
42
46
Closes #2734
Original file line number Diff line number Diff line change @@ -309,13 +309,13 @@ def scope(self) -> nodes.LocalsDictNodeNG:
309
309
raise ParentMissingError (target = self )
310
310
return self .parent .scope ()
311
311
312
- def root (self ) -> nodes .Module :
312
+ def root (self ) -> nodes .Module | nodes . Unknown :
313
313
"""Return the root node of the syntax tree.
314
314
315
315
:returns: The root node.
316
316
"""
317
317
if not (parent := self .parent ):
318
- assert isinstance (self , nodes .Module )
318
+ assert isinstance (self , ( nodes .Module , nodes . Unknown ) )
319
319
return self
320
320
321
321
while parent .parent :
Original file line number Diff line number Diff line change @@ -500,6 +500,21 @@ def _get_option(self, option):
500
500
assert node .inferred ()[0 ].value == "mystr"
501
501
502
502
503
+ def test_regression_root_is_not_a_module () -> None :
504
+ """Regression test for #2672."""
505
+ node : nodes .Attribute = _extract_single_node (
506
+ textwrap .dedent (
507
+ """
508
+ a=eval.__get__(1).__gt__
509
+
510
+ @a
511
+ class c: ...
512
+ """
513
+ )
514
+ )
515
+ assert node .name == "c"
516
+
517
+
503
518
def test_regression_no_crash_during_build () -> None :
504
519
node : nodes .Attribute = extract_node ("__()" )
505
520
assert node .args == []
You can’t perform that action at this time.
0 commit comments