Python: calls to a typing.overload'ed function link to the first @overload stub, not the implementation
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- C
- Sterne
- 73.2k
- Forks
- 4.7k
- Ø Merge
- 3 Std. 37 Min.
- Gemergte PRs (30 T.)
- 533
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus colbymchenry/codegraph
-
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 functionEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
colbymchenry/codegraph#3093 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Windows: npm-shim spawnSync missing windowsHide flashes a console window on every MCP server launchOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
colbymchenry/codegraph#3054 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
colbymchenry/codegraph#2974 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
colbymchenry/codegraph#2959 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
colbymchenry/codegraph#1900 · 2 Kommentare · 5 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in colbymchenry/codegraph
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
STMicroelectronics/STSELib#128 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
CCExtractor/ccextractor#2440 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
LSP: Invalid buffer id in previous_result_ids during workspace/diagnostic/refreshEvtl. vergeben @sharky720 hat das heute übernommen. Offendiagnostic lsp
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
neovim/neovim#42629 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
c first-contributor first-contributors good first issue help wanted medium up-for-grabs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
fork-commit-merge/fork-commit-merge#8539 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag