Python: `.get()`/`.update()` on a typed project-class instance get no edge (dropped as builtins)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 40/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python, typescript
- Domain
- tooling
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- C
- Stars
- 73.2k
- Forks
- 4.7k
- Avg merge
- 2h 13m
- Merged PRs (30d)
- 418
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from colbymchenry/codegraph
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
colbymchenry/codegraph#2634 ·
Maintainers usually reply within 1 day
-
Windows: bundled Node v24.16.0 can abort at exit (nodejs/node#56645); please bundle Node >= 24.20.0Possibly taken @Ancienttwo claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
colbymchenry/codegraph#2617 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Under an hour Newbie friendliness 72/100
colbymchenry/codegraph#2482 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
colbymchenry/codegraph#1900 · 2 comments · 5 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
colbymchenry/codegraph#1700 ·
Maintainers usually reply within 1 day
All issues in colbymchenry/codegraph
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
OpenPrinting/cups#1772 ·
Maintainers usually reply within 1 day
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
antoxa2584x/nfsu2-sw#44 · 1 reaction ·
Maintainers usually reply within 1 day