Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Python: `.get()`/`.update()` on a typed project-class instance get no edge (dropped as builtins)

未关闭
#2,583 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 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 = {} then d.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, …); only get and update were run.
  • self.<attr>.get() and parameters annotated with the class (def f(reg: SystemPackRegistry)).
  • The native kernel extractor (only CODEGRAPH_KERNEL=0 was run).
  • Windows and macOS.
主要语言
C
星标
73.2k
派生
4.7k
平均合并
13 小时 27 分钟
30 天内合并 PR
518

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

colbymchenry/codegraph 的其他 Issue

查看 colbymchenry/codegraph 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。