Skip to content

Commit 0011e7f

Browse files
temyurchenkoDanielNoord
authored andcommitted
add the parent node to "__main__"
Not having a parent leads to weird situations, like `root()` returning the node itself, not a `Module`.
1 parent 7954bac commit 0011e7f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ def getattr(
354354
if name in self.special_attributes and not ignore_locals and not name_in_locals:
355355
result = [self.special_attributes.lookup(name)]
356356
if name == "__name__":
357-
result.append(const_factory("__main__"))
357+
main_const = const_factory("__main__")
358+
main_const.parent = AstroidManager().builtins_module
359+
result.append(main_const)
358360
elif not ignore_locals and name_in_locals:
359361
result = self.locals[name]
360362
elif self.package:

0 commit comments

Comments
 (0)