Skip to content

feat!: parse contextual generic type bases - #30

Merged
exKAZUu merged 4 commits into
mainfrom
feat/contextual-generic-bases
Oct 20, 2026
Merged

exKAZUu merged 4 commits into
mainfrom
feat/contextual-generic-bases

Conversation

@exKAZUu

@exKAZUu exKAZUu commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Why

Annotations such as value: match[int] retain a value-subscript tree and miss the type captures expected from a generic annotation. Recognizing these contextual names must also preserve ordinary modern print[...] expressions and supported Python2 statements.

Requirements

  • required: Improve our forked tree-sitter repositories as much as possible, ignoring backward compatibility (the syntax tree structure may change freely); review our issues and upstream issues, PRs and recent commits, and create a dedicated nonduplicate PR for each item that warrants resolution.
  • required: Complete each remaining PR, then run review-booster, complete-pr and release in that order.
  • required: Preserve accepted Python syntax, ordinary value-expression trees, source ranges, highlight roles and incremental/fresh parsing agreement.
  • chosen: Recognize bare match, print, exec and lazy as generic bases in annotation contexts, reusing the existing contextual-name/member-base rule. The parent parser leaves these annotation bases as value subscripts and misses their type captures, while ordinary value uses must keep their expression trees.
  • chosen: Give print/exec contextual type names the existing keyword_identifier priority and retain the explicit print/value/generic and list-splat/type-expression conflicts. A helper-only candidate incorrectly changed two ordinary modern print subscripts to Python2 print statements; the shared priority and ambiguity rules preserve all eighteen legacy controls and accept two CPython-valid print/exec type-parameter bounds rejected by the parent.
  • chosen: Make this a separate follow-up to the qualified-generic-operand change, publishing only after that prerequisite is merged and the combined main is validated, so the dedicated PR contains only this item.
  • chosen: Publish a major version for changed annotation ASTs and type captures; retain runtime 2.x compatibility because this item does not change the runtime ABI.

Customer Summary

Generic annotations recognize match, print, exec and lazy as type bases. Ordinary value subscripts keep their expression trees. Valid type-parameter bounds named print or exec also parse successfully.

Technical Summary

generic_type reuses _default_member_base. Contextual print/exec type names use the existing keyword-identifier priority, and explicit ambiguities retain the value/legacy-print and list-splat alternatives. README documents the annotation behavior and the next major crate version. Review the shared type-parameter-name priority against ordinary print statements and expression contexts.

Testing

  • Canonical generation, 207 native and Wasm corpus cases, and sixteen focused tests in eight files passed. The new public tests were RED against the prerequisite parser and cover type captures, ordinary value exclusions, following statements and a real incremental edit; the final bound-plus-generic context and verification also passed.
  • 315 CPython-oracle cases (245 valid), 56 contextual-name cases and eighteen complete legacy-tree/capture controls passed without introduced rejections, lost following definitions or changed ordinary trees. Additional 98 bound/qualified-base controls preserve previously accepted trees/captures and fix two CPython-valid bound names.
  • Nested types through depth 160 and unions through 512 operands retain complete structure/captures.
  • After merging current main (comparison operand fields), regeneration reproduced the merged src/ byte for byte; bun run verify and the contextual-base and comparison-operand tests passed. Full CI runs the complete suite.

Notes

This is a breaking annotation-AST and highlighting change. Seven pre-existing code-gauge errors and 46 warnings remain outside changed code: GrammarTests.testFuncdef in both Python2 variants (159 NCSS each), the corresponding function in both Python3 variants (187 each), the Python3.8 example file (1,200 NCSS) and its test_funcdef (232 NCSS), and external scanner dispatch (complexity 175/202 NCSS). Refactoring imported fixtures or the unrelated scanner would expand this type-base change. The intentional LF/CRLF fixture duplicates would be suitable for a code-gauge exclusion; no configuration exclusion is added. Runtime 2.x remains required.

exKAZUu and others added 4 commits October 19, 2026 17:45
Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
Reuse contextual type names for annotation generic bases while preserving
ordinary value subscripts and legacy print-statement parsing.

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
Retain the verified contextual-base source tree while recording the
released prerequisite as an ancestor.

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
Co-authored-by: WillBooster (Claude Code) <agent@willbooster.com>
@exKAZUu exKAZUu self-assigned this Oct 20, 2026
@exKAZUu
exKAZUu merged commit 9ea6e73 into main Oct 20, 2026
12 checks passed
@exKAZUu
exKAZUu deleted the feat/contextual-generic-bases branch October 20, 2026 13:29
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