Skip to content

Commit

Permalink
add the parent node to "__main__"
Browse files Browse the repository at this point in the history
Not having a parent leads to weird situations, like `root()` returning
   the node itself, not a `Module`.
  • Loading branch information
temyurchenko authored and DanielNoord committed Sep 9, 2024
1 parent 7954bac commit 0011e7f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ def getattr(
if name in self.special_attributes and not ignore_locals and not name_in_locals:
result = [self.special_attributes.lookup(name)]
if name == "__name__":
result.append(const_factory("__main__"))
main_const = const_factory("__main__")
main_const.parent = AstroidManager().builtins_module
result.append(main_const)
elif not ignore_locals and name_in_locals:
result = self.locals[name]
elif self.package:
Expand Down

0 comments on commit 0011e7f

Please sign in to comment.