Skip to content

fix(python): a parameterized base links its class, like class Leaf(Base[str]) - #2998

Draft
JosefAschauer wants to merge 1 commit into
colbymchenry:mainfrom
JosefAschauer:fix/python-generic-base
Draft

JosefAschauer wants to merge 1 commit into
colbymchenry:mainfrom
JosefAschauer:fix/python-generic-base

Conversation

@JosefAschauer

@JosefAschauer JosefAschauer commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A Python class with a parameterized base, class Leaf(Base[str]), has no extends edge. The grammar parses Base[str] in the base list as a subscript, and the base-list reader only took bare identifiers and attributes, so the base was skipped. Everything that follows the class hierarchy misses such a class. This is the Python counterpart of #2856 (Java/TS Store<String>), and the "generic bases" item left open in #2076.

The resolver also reads a class's base list as text (pythonBases in name-matcher.ts, behind module-global and self. dispatch). It looked up Base[str] verbatim and split Pair[str, int] at its inner comma, so current = Leaf() then current.run() did not reach Base.run.

Fix

  • Extraction, both arms: a subscript base is unwrapped to its value field before the existing identifier | attribute check, in src/extraction/tree-sitter.ts and in the kernel's codegraph-kernel/src/python.rs. The reference sits at the value's start, the position the plain form had.
  • Resolver: pythonBases drops bracketed type arguments (nested ones too) before splitting the list.
  • Not linked, as before: Generic[T] / Protocol[T] (outside the project, like their plain forms), a computed base like make()[0], a subscript of a subscript like Base[int][str], and keyword arguments like metaclass=Meta.

Validation

  • New __tests__/python-generic-bases.test.ts, run on both arms: wasm (CODEGRAPH_KERNEL=0) and kernel (CODEGRAPH_KERNEL_LANGS=python; skipped when no kernel is staged). 16 tests:

    • Base[str], Base[list[int]], Pair[str, dict[str, int]], a base written over several lines, a mixed list (Mixin, Base[str]), and models.Base[int] all link like their plain forms;
    • a keyword argument, a computed base and Base[int][str] link nothing; Generic[T] links nothing;
    • a module global holding Leaf / Two resolves run to Base::run / Pair::run, with a same-named decoy class in the file.

    Each fix was mutation-checked on its own: disabling the wasm unwrap fails only wasm tests, disabling the kernel unwrap fails only kernel tests, and disabling the pythonBases change fails the module-global test on both arms.

  • npx tsc --noEmit: clean. Kernel built with npm run build:kernel.

  • Full suite on Linux with the kernel staged: 9281 passed, 4 failed. The failures are environmental and also fail on main:

    • bundle-launcher ×2: no zip binary.
    • cli-sync ×2: the host runs Node 26, which prints the unsupported-Node banner.
  • Together with feat(resolution): link Python base methods to their overrides (python-override) #2076, Base.run gets its override link to Leaf.run on both arms.

Follow-ups

Independent of #2076.

🤖 Generated with Claude Code

https://claude.ai/code/session_018hJjBUPFiLSFBssshFwHzq

…se[str])

The base-list reader took only bare identifiers and attributes, so a
subscripted base (`Base[str]`, `models.Base[int]`) produced no `extends`
reference and the class had no supertype edge. Both arms (wasm
TreeSitterExtractor and the kernel's python.rs) now name the subscript's
value. Generic[T] and other bases outside the project stay unresolved, as
their plain forms do.

The resolver's own text reader of a class's base list (pythonBases, used by
module-global and self. dispatch) split `Pair[str, int]` at its inner comma
and looked up `Base[str]` verbatim; it now drops bracketed type arguments
first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018hJjBUPFiLSFBssshFwHzq

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant