Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Python: calls to a typing.overload'ed function link to the first @overload stub, not the implementation

未关闭
#2,963 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
tooling

调研方向

Reproduce with the supplied pkg/deco.py and use.py snippets, then inspect the emitted calls edges for command and Prompt.ask; the expected targets are the implementation defs at lines 12 and 30, not the first @overload stubs. Start by locating the Python call-resolution path that maps a call to an indexed definition, and check how it treats multiple defs sharing a name and decorators such as @classmethod. Done means the example’s callers and impact reach the implementation, the run to real_work path is intact, and Python resolution tests cover overload plus classmethod overload cases.

由索引模型根据 Issue 内容生成。

描述

Calls to a Python function or method declared with typing.overload link to the first @overload stub, whose body is just .... The real implementation, the undecorated def that runs, gets no callers, even though its body holds all the callees.

# pkg/deco.py
import typing as t


@t.overload
def command(name: t.Callable) -> int: ...          # line 5


@t.overload
def command(name: str | None = None) -> str: ...   # line 9


def command(name=None):                            # line 12, the implementation
    return real_work(name)


def real_work(n):
    return n


class Prompt:
    @t.overload
    @classmethod
    def ask(cls, p: str) -> str: ...               # line 23

    @t.overload
    @classmethod
    def ask(cls, p: str, d: int) -> int: ...

    @classmethod
    def ask(cls, p, d=None):                       # line 30, the implementation
        return real_work(p)

# pkg/__init__.py
from .deco import command, Prompt

# use.py
import pkg
from pkg import command, Prompt


@pkg.command()
def cli():
    pass


def run():
    command("x")
    Prompt.ask("y")
call edge on main expected
@pkg.command() command at line 5 (stub) line 12
command("x") command at line 5 (stub) line 12
Prompt.ask("y") ask at line 23 (stub) line 30

All six defs are indexed as separate nodes. The stubs have no callees, and the implementations have the callees but no callers. So callers/impact on the implementation come back empty, the call path from run to real_work breaks at the stub, and the implementation looks unreferenced.

Reproduced on main at 72f398af, with CODEGRAPH_KERNEL=0 and with the native kernel. Linux/WSL2, Node 22.23.2.

Where it shows up. Libraries that type their public API with overloads are hit hardest. Checking every Python calls edge against jedi's goto-definition:

  • In click (2247b35), command in src/click/decorators.py has stubs at lines 138, 144, 153 and 163 and the implementation at 168. 345 call edges land on the line-138 stub and 2 on the implementation. Most of click's 473 disagreeing import edges are this (group, edit, progressbar, prompt, convert_type, …).
  • In rich (9d8f9a3), Confirm.ask / Prompt.ask and rich.progress.open land on their first stub the same way.

Expected. For a Python name with @overload stubs plus an implementation, link calls to the implementation (the def without @overload). If a stub is kept for its signature, the implementation should still be the callee. #2213 ("any call reaches the overload its arguments fit") covers languages whose overloads are separate implementations. A Python call always runs the one undecorated def.

Related: #2213.

主要语言
C
星标
73.2k
派生
4.7k
平均合并
3 小时 31 分钟
30 天内合并 PR
546

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

colbymchenry/codegraph 的其他 Issue

查看 colbymchenry/codegraph 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。