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 d7590bd
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 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 @@ -500,7 +499,7 @@ def object_build(
if alias == "__class__" and child.parent is None:
child.parent = self._done[self._module]

Check warning on line 500 in astroid/raw_building.py

View check run for this annotation

Codecov / codecov/patch

astroid/raw_building.py#L500

Added line #L500 was not covered by tests
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 +511,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 d7590bd

Please sign in to comment.