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

Abierto
#2,963 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@nilotpal-n7 ya está trabajando en esto.

Desde el 1/11/2026.

  • #3216 de @nilotpal-n7 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
tooling

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), 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.

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de colbymchenry/codegraph

Todos los issues de colbymchenry/codegraph

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.