Python: calls to a typing.overload'ed function link to the first @overload stub, not the implementation
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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),
commandinsrc/click/decorators.pyhas 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 disagreeingimportedges are this (group,edit,progressbar,prompt,convert_type, …). - In rich (9d8f9a3),
Confirm.ask/Prompt.askandrich.progress.openland 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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
colbymchenry/codegraph 的其他 Issue
-
A `../` entry in package.json `workspaces` makes a folder outside the project count as a workspace package, and a call gets linked to the wrong function可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
colbymchenry/codegraph#3093 ·
维护者通常 1 天内回复
-
Windows: npm-shim spawnSync missing windowsHide flashes a console window on every MCP server launch未关闭
难度 2/5 1-3 小时 新手友好度 86/100
colbymchenry/codegraph#3054 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
colbymchenry/codegraph#2974 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
colbymchenry/codegraph#2959 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
colbymchenry/codegraph#1900 · 2 条评论 · 5 个 reaction ·
维护者通常 1 天内回复
查看 colbymchenry/codegraph 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
-
难度 1/5 1 小时以内 新手友好度 80/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
eunomia-bpf/bpfix#7 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
python-pillow/Pillow#10370 · 1 条评论 ·
维护者通常 1 天内回复