Skip to content

Python: self.attr(...) on an instance attribute links an unrelated, un-imported module function of the same name #3039

Closed as duplicate

Description

@inth3shadows

What happens

A call through an instance attribute (self.out = Layer() in __init__, then self.out(x)) links to a module-level function of the same name in a different module. The calling file never imports that module.

# other/features.py
def out(x):
    return x

# lab/model.py
class Layer:
    def __call__(self, x):
        return x


class MLP:
    def __init__(self):
        self.out = Layer()

    def forward(self, x):
        return self.out(x)
  • Expected: no edge from MLP.forward to other/features.py: out. Either link to Layer (through __call__) or link nothing.
  • Actual on main (60b0d7a): forward calls other/features.py: out, with resolvedBy: exact-match.

Real cases:

  • a PyTorch model whose forward calls self.out(...) (an nn.Linear set in __init__) links to a module-level variable out in an unrelated script;
  • a test's self.run("git", ...) (bound in setUp) links to a free function run in a harness module the test doesn't import.

Found by diffing codegraph's call edges against scip-python on several Python repos.

Activity

  1. inth3shadows commented on Oct 29, 2026

    @inth3shadows
    ContributorAuthor

    Duplicate of #2958, which I filed earlier for the same bug. The new shapes found here (a module-level variable as the target, and an attribute bound by tuple unpacking in setUp) are added there as a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions