Python: `.get()`/`.update()` on a typed project-class instance get no edge (dropped as builtins)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 40/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- python, typescript
- 领域
- tooling
调研方向
Start with isBuiltInOrExternal and PYTHON_BUILT_IN_METHODS in src/resolution/index.ts, where the Python builtin-method filter drops dotted refs before matchMethodCall runs. Reproduce with the two-file example (loader.py and test_packs.py) and check which calls get edges. Done means lines 6, 11 and 12 resolve to SystemPackRegistry::get and ::update while the module-scope d = {}; d.get(...) case stays dropped.
由索引模型根据 Issue 内容生成。
描述
Summary
In Python, a call to a project method named like a builtin collection method (get, update, items, pop, …) is dropped as a builtin unless the receiver variable's name, capitalized, is the name of a project class. This happens even when the receiver's type is known: reg = SystemPackRegistry(); reg.get("y") gets no edge, while the same code with the methods renamed, or with the variable named systemPackRegistry, resolves at 0.9.
Reproduction (verified)
On main at 8fe31569, built from source, Linux (WSL2), Node 22.23.2, WASM extractor (CODEGRAPH_KERNEL=0). Two files:
# loader.py
class SystemPackRegistry:
def get(self, pack_id):
return pack_id
def update(self):
return None
def load_registry() -> SystemPackRegistry:
return SystemPackRegistry()
# test_packs.py
from loader import SystemPackRegistry, load_registry
def test_pack():
registry = load_registry()
return registry.get("x") # line 6
def test_ctor():
reg = SystemPackRegistry()
reg.update() # line 11
return reg.get("y") # line 12
codegraph init -i, then the calls / imports / instantiates edges:
load_registry -instantiates-> SystemPackRegistry [loader.py:1] @10 exact-match/0.9
test_packs.py -imports-> SystemPackRegistry [loader.py:1] @1 import/0.9
test_packs.py -imports-> load_registry [loader.py:9] @1 import/0.9
test_pack -calls-> load_registry [loader.py:9] @5 import/0.9
test_ctor -instantiates-> SystemPackRegistry [loader.py:1] @10 import/0.9
There is no edge for lines 6, 11 or 12.
Expected: test_ctor -calls-> SystemPackRegistry::update (line 11) and -> SystemPackRegistry::get (line 12), and test_pack -calls-> SystemPackRegistry::get (line 6), as in the controls below.
Controls, same build:
| Change | Line 6 | Line 11 | Line 12 |
|---|---|---|---|
| as above | none | none | none |
methods renamed get→lookup, update→refresh |
SystemPackRegistry::lookup instance-method/0.7 |
SystemPackRegistry::refresh instance-method/0.9 |
SystemPackRegistry::lookup instance-method/0.9 |
reg renamed systemPackRegistry |
none | SystemPackRegistry::update instance-method/0.9 |
SystemPackRegistry::get instance-method/0.9 |
So the resolver can type both receivers, but the builtin filter runs first and decides from the variable's name alone.
Likely cause (inferred from reading the code)
isBuiltInOrExternal runs before any resolution strategy. For a dotted Python ref whose method is in PYTHON_BUILT_IN_METHODS (get, update, items, pop, read, write, close, …), it keeps the ref only if the capitalized receiver (reg → Reg) is a project class name, or the receiver is an imported project module (#1681). Otherwise it returns true, and the ref is discarded before matchMethodCall can infer the receiver's type from reg = SystemPackRegistry() or -> SystemPackRegistry.
One option is to leave these refs to matchMethodCall when the receiver has a local declaration that the existing receiver-type inference can type, and drop them only when it can't.
Related
- #1681 / #1749: the same filter dropped
module.append()on an imported project module. The fix added the project-module exception, not a typed-receiver one. - #1652 / #1776: the filter's module-scope collection check (
d = {}thend.get(...)). That case should still be dropped. - #1230: the original Python builtin-name false positives this filter guards against.
- #1947 (open PR): the opposite direction, library-method names on untyped receivers binding to project methods. This issue is about typed receivers losing real edges.
A build of the inth3shadows fork that carries open PRs #1704 and #1926 gives the same output.
Not checked
- Other names in the set (
items,pop,read,close, …); onlygetandupdatewere run. self.<attr>.get()and parameters annotated with the class (def f(reg: SystemPackRegistry)).- The native kernel extractor (only
CODEGRAPH_KERNEL=0was run). - Windows and macOS.
- 主要语言
- C
- 星标
- 73.2k
- 派生
- 4.7k
- 平均合并
- 13 小时 27 分钟
- 30 天内合并 PR
- 518
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
colbymchenry/codegraph 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 90/100
colbymchenry/codegraph#2634 ·
维护者通常 1 天内回复
-
Windows: bundled Node v24.16.0 can abort at exit (nodejs/node#56645); please bundle Node >= 24.20.0可能已有人在做 @Ancienttwo 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
colbymchenry/codegraph#2617 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1 小时以内 新手友好度 72/100
colbymchenry/codegraph#2482 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
colbymchenry/codegraph#1900 · 2 条评论 · 5 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
colbymchenry/codegraph#1700 ·
维护者通常 1 天内回复
查看 colbymchenry/codegraph 的全部 Issue
相似的 Issue
-
v9.6.0: CMake incorrectly enforces presence of libevdev可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
IoTSDK
难度 2/5 1-3 小时 新手友好度 70/100
Azure/azure-iot-sdk-c#2776 ·
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
bug Component component: net
难度 2/5 1-3 小时 新手友好度 78/100
RT-Thread/rt-thread#11913 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
contiki-ng/contiki-ng#3289 ·
维护者通常 3 天内回复