Skip to content

[Bug]: Python lambda defaults call unrelated same-file functions when enclosing parameters shadow them #5418

Open

Description

@melhusl-hs

What happened?

A call in a lambda default can link to a same-file module function even when an enclosing function parameter binds that name. The extractor emits an EXTRACTED calls edge to the module function. The call goes through a parameter whose target is unknown to the extractor.

Steps to reproduce

Save as probe.py:

def handler():
    return "module"

def factory(handler):
    return lambda cb=handler(): cb

def outer(handler):
    def inner():
        return lambda cb=handler(): cb
    return inner

Run this from the directory containing the file:

from pathlib import Path
from graphify.extract import extract_python

result = extract_python(Path("probe.py"))
labels = {node["id"]: node["label"] for node in result["nodes"]}
for edge in result["edges"]:
    if edge["relation"] == "calls":
        print(labels[edge["source"]], labels[edge["target"]], edge["confidence"])

Graph output

factory() handler() EXTRACTED
inner() handler() EXTRACTED

Expected neither edge. factory(lambda: "parameter")() and outer(lambda: "parameter")()() both return "parameter".

Environment and related work

Reproduced from source on Linux with Python 3.12, Graphify 0.9.115, at v8 commit a3db62f680cd and draft #5417's original head ba96a3d7616f. The reproducer uses structural extraction without provider credentials.

The same-file bare-call lookup can select a module symbol before checking enclosing function bindings. The regression should cover both the function parameter and the captured parameter while preserving genuine local callables and explicit imports.

Related to #5417 and #3607.

Activity

  1. github-actions commented on Nov 23, 2026

    @github-actions

    Thanks for opening this issue, @melhusl-hs. 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.

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