Skip to content

Python: calls on module-level class instances get no calls edge (g = Svc(); def f(): g.m()), incl. lowercase class rebound to instance #4970

Closed

Description

@shounaksarkar

Version: graphifyy 0.9.101 (latest), code-only, GRAPHIFY_BACKEND=none

Summary

A method call on a class instance created at module scope gets no calls edge when it's made inside a function. This covers a plain singleton (g = Svc()) and a lowercase class rebound to its own instance (svc = svc(app), a common Flask-style pattern). It's the Python version of #3101 (Pascal) and #1698 (Kotlin).

On a ~1,300-file production backend this drops most calls into core service classes: 102 such rebinds across 57 files. A core write method showed 0 callers where grep finds 8+, and the top-degree nodes came out as schema base classes.

Repro

# pkg/__init__.py  (empty)

# pkg/svc.py
class Svc:
    def create(self): return 1

class lower_svc:
    def __init__(self, app): self.app = app
    def create(self): return 2

# pkg/caller.py
from .svc import Svc, lower_svc

g = Svc()
lower_svc = lower_svc(None)

def a(): g.create()          # expected: calls -> Svc.create
def b(): lower_svc.create()  # expected: calls -> lower_svc.create
def c():
    x = Svc(); x.create()    # control

GRAPHIFY_BACKEND=none graphify update . --no-cluster

Actual calls edges: only c() -> Svc and c() -> .create(). a() and b() get nothing.

Likely cause (reading v8)

  • _python_local_class_bindings (extractors/engine.py) collects bindings only from a function's own params and locals. Module-scope assignments never set receiver_type.
  • With no receiver_type, _resolve_python_member_calls (extract.py ~5331–5364) falls back to two branches. The class branch requires receiver[:1].isupper(), so a lowercase class never takes it. The module branch only matches imported modules. Both miss.
  • An X = X(...) rebind would also hit the "import + constructor" poisoning rule.

Suggested fix

Collect module-scope name = ClassName(...) bindings and let functions inherit them unless they shadow the name locally. Treat X = X(...), where the right-hand X resolves to exactly one class, as an instance of that class. Emit these edges as INFERRED, like the existing typed-receiver branch.

Activity

  1. github-actions commented on Nov 3, 2026

    @github-actions

    Thanks for opening this issue, @shounaksarkar. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. added a commit that references this issue on Nov 3, 2026
    dce3af7
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions