Skip to content

Commit

Permalink
fixup! control setting nodes as local outside of the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
temyurchenko committed Sep 27, 2024
1 parent 2ae573b commit 17360c4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions astroid/raw_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,9 @@ def _build_from_function(
filename = getattr(code, "co_filename", None)
if filename is None:
return object_build_methoddescriptor(node, member)
elif filename != getattr(module, "__file__", None):
return build_dummy(member)
else:
if filename == getattr(module, "__file__", None):
return object_build_function(node, member)
return build_dummy(member)


def _safe_has_attribute(obj, member: str) -> bool:
Expand Down Expand Up @@ -497,10 +496,8 @@ def object_build(
child = object_build_class(node, member)
# recursion
self.object_build(child, member)
if alias == "__class__" and child.parent is None:
child.parent = self._done[self._module]
elif inspect.ismethoddescriptor(member):
child = object_build_methoddescriptor(node, member)
child: nodes.NodeNG = object_build_methoddescriptor(node, member)
elif inspect.isdatadescriptor(member):
child = object_build_datadescriptor(node, member)
elif isinstance(member, _CONSTANTS):
Expand All @@ -512,12 +509,12 @@ def object_build(
# methods aren't caught by isbuiltin branch.
child = _build_from_function(node, member, self._module)
elif _safe_has_attribute(member, "__all__"):
child = build_module(alias)
child: nodes.NodeNG = build_module(alias)
# recursion
self.object_build(child, member)
else:
# create an empty node so that the name is actually defined
child = build_dummy(member)
child: nodes.NodeNG = build_dummy(member)
if child not in node.locals.get(alias, ()):
node.add_local_node(child, alias)
return None
Expand Down

0 comments on commit 17360c4

Please sign in to comment.