Python: a local built through a module attribute (x = pkg.Cls()) is typed by its variable name
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C
- Star
- 73.2k
- Fork
- 4.7k
- Merge trung bình
- 3 giờ 15 phút
- Pull request đã merge (30 ngày)
- 576
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của colbymchenry/codegraph
-
mcp: a projectPath naming a file inside a project returns isError ("Path is not a directory")Có thể đã có người làm @maxmilian đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
colbymchenry/codegraph#2982 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mcp: a non-object tools/call arguments crashes the handler and is reported as an internal error to retryCó thể đã có người làm @kjgggggg đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
colbymchenry/codegraph#2981 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
colbymchenry/codegraph#2974 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
search: FTS special characters are deleted, not separated, so leaf(entry) matches nothingCó thể đã có người làm @kjgggggg đã nhận 2 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
colbymchenry/codegraph#2971 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Security Vulnerabiliy] Vulnerable bundled `node.exe` detected (Node2Shell - CVE-2026-111497)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
colbymchenry/codegraph#2959 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của colbymchenry/codegraph
Issue tương tự
-
vim.filetype.match() prefixes a URL buffer name with the cwd before passing it to filetype functionsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
stream_curl: retry_count never resets after a successful reconnect, so long sequential streams die after 5 dropsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
mpv-player/mpv#18728 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
followup Prio 📌
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
cyrusimap/cyrus-imapd#6640 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
Maintainer thường phản hồi trong vòng 1 ngày