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?
3737=============================
3838Release date: TBA
3939
40+ * Fix a crash when the root of a node is not a module but is unknown.
41+
42+ Closes #2672
43+
4044* Fix a crash when parsing an empty arbitrary expression with ``extract_node`` (``extract_node("__()")``).
4145
4246 Closes #2734
Original file line number Diff line number Diff line change @@ -309,13 +309,13 @@ def scope(self) -> nodes.LocalsDictNodeNG:
309309 raise ParentMissingError (target = self )
310310 return self .parent .scope ()
311311
312- def root (self ) -> nodes .Module :
312+ def root (self ) -> nodes .Module | nodes . Unknown :
313313 """Return the root node of the syntax tree.
314314
315315 :returns: The root node.
316316 """
317317 if not (parent := self .parent ):
318- assert isinstance (self , nodes .Module )
318+ assert isinstance (self , ( nodes .Module , nodes . Unknown ) )
319319 return self
320320
321321 while parent .parent :
Original file line number Diff line number Diff line change @@ -500,6 +500,21 @@ def _get_option(self, option):
500500 assert node .inferred ()[0 ].value == "mystr"
501501
502502
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+
503518def test_regression_no_crash_during_build () -> None :
504519 node : nodes .Attribute = extract_node ("__()" )
505520 assert node .args == []
You can’t perform that action at this time.
0 commit comments