Python: a local built through a module attribute (x = pkg.Cls()) is typed by its variable name
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start with the Python call-resolution code that types a local from its initializer; reproduce with the pkg/_client.py and use.py fixture in the issue, where client.fetch() wrongly resolves to Client.fetch. Check the instantiates handling for pkg.AsyncClient() versus from pkg import AsyncClient. Done when all four functions link to AsyncClient.fetch at line 7 and the with form is typed too.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
A Python local assigned from a constructor called through a module attribute (client = pkg.AsyncClient()) gets no type. Its method calls then fall to the receiver-name guess, which links client.fetch() to the class named like the variable, Client, even though the code just built an AsyncClient.
# pkg/_client.py
class Client:
def fetch(self, url): # line 2
return url
class AsyncClient:
async def fetch(self, url): # line 7
return url
# pkg/__init__.py
from ._client import Client, AsyncClient
# use.py
import pkg
from pkg import AsyncClient
async def attr_named_client():
client = pkg.AsyncClient()
await client.fetch("u")
async def attr_named_c():
c = pkg.AsyncClient()
await c.fetch("u")
async def from_named_client():
client = AsyncClient()
await client.fetch("u")
async def with_named_client():
async with pkg.AsyncClient() as client:
await client.fetch("u")
| function | edge on main |
expected |
|---|---|---|
attr_named_client (client = pkg.AsyncClient()) |
Client.fetch (line 2, instance-method) ✗ |
AsyncClient.fetch (line 7) |
with_named_client (async with pkg.AsyncClient() as client) |
Client.fetch ✗ |
AsyncClient.fetch |
attr_named_c (c = pkg.AsyncClient()) |
none | AsyncClient.fetch |
from_named_client (from pkg import AsyncClient) |
AsyncClient.fetch ✓ |
same |
The instantiates edge for pkg.AsyncClient() resolves correctly in every case. Only the local's type is lost, and the name guess fills the gap with the wrong class.
Reproduced on main at 25776014, with CODEGRAPH_KERNEL=0 and with the native kernel. Linux/WSL2, Node 22.23.2. (3f8e8b0f and 69cddc01 since then touch only Rust and the changelog.)
Where it shows up. httpx (b5addb6) uses exactly this: async with httpx.AsyncClient(...) as client: await client.get(url). Checking every Python calls edge against jedi's goto-definition, about 70 httpx edges disagree this way. Their client.get / post / send / stream / put / options / … calls link to the sync Client methods (httpx/_client.py lines 771–1234) instead of AsyncClient's (lines 1485–1949), for example every request in tests/client/test_async_client.py. Calling a project's own classes through the module (import mymod; x = mymod.Thing()) is common Python, so this isn't specific to httpx.
Expected. Type the local from module.Class(...) the same way as from a directly imported Class(...), and type with …() as x / async with …() as x from the context manager's class. (In another fixture, async with AsyncClient() as client with a directly imported AsyncClient also linked client.get() to Client.get, so the with form may need its own fix.) Failing that, don't let the receiver-name guess answer when the initializer is a call on a project class.
Related: #2946 (the same variable-name guess in TypeScript), #2821, #2175.
- Lingua principale
- C
- Stelle
- 73.2k
- Fork
- 4.7k
- Merge medio
- 3h 31m
- PR unite (30g)
- 546
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di colbymchenry/codegraph
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
colbymchenry/codegraph#3093 ·
I maintainer di solito rispondono entro 1 giorno
-
Windows: npm-shim spawnSync missing windowsHide flashes a console window on every MCP server launchAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
colbymchenry/codegraph#3054 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
colbymchenry/codegraph#2974 ·
I maintainer di solito rispondono entro 1 giorno
-
[Security Vulnerabiliy] Vulnerable bundled `node.exe` detected (Node2Shell - CVE-2026-111497)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
colbymchenry/codegraph#2959 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
codegraph ui - does not workAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
colbymchenry/codegraph#1900 · 2 commenti · 5 reazioni ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di colbymchenry/codegraph
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
area:docs area:stdlib found-by:duet-audit kind:docs-drift
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
InauguralSystems/EigenScript#2251 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
flux-framework/flux-coral2#513 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ly05010419/MacNativeGames#1420 ·
I maintainer di solito rispondono entro 1 giorno
-
Isaac workingAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
seedds/nxnative#763 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno