Python: calls to a typing.overload'ed function link to the first @overload stub, not the implementation
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C
- Estrellas
- 73.2k
- Forks
- 4.7k
- Merge medio
- 3 h 39 min
- PR fusionados (30 d)
- 528
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de colbymchenry/codegraph
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
colbymchenry/codegraph#3228 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
colbymchenry/codegraph#3223 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
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 functionPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
colbymchenry/codegraph#3093 ·
Los mantenedores suelen responder en 1 día
-
Windows: npm-shim spawnSync missing windowsHide flashes a console window on every MCP server launchAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
colbymchenry/codegraph#3054 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
colbymchenry/codegraph#2974 ·
Los mantenedores suelen responder en 1 día
Todos los issues de colbymchenry/codegraph
Issues similares
-
Linux: out-of-bounds `keyMap` read when a keyboard with an `EV_ABS` axis is opened as a joystickAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
JustAResearcher/gpu-unlock-ada#136 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
esnet/iperf#2101 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
-
Preserve final logical line at EOF in db2ldif_read_ldif_line()Posiblemente ocupada @ccsimplyspolit la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
389ds/389-ds-base#8088 ·
Los mantenedores suelen responder en 2 días
-
ai-driven-fuzzing bug Minor
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
linagora/open-bastion#431 ·
Los mantenedores suelen responder en 1 día