mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-10-27 06:53:11 +08:00
Round 2/3 parity push. Three connected gap fixes that share an annotation- parser and a generic-aware iterable model. Annotation parser upgrade: - py_resolve_annotation now turns subscripted forms into structured types rather than stripping. `Optional[Foo]` -> UNION(NAMED(Foo), None). `Union[A, B]` -> UNION. `list[Foo]` / `dict[K, V]` / `Iterable[T]` -> TEMPLATE with arg list. `X | Y` (PEP 604) handled at depth zero. - New py_parse_type_text_qn variant: same parser without scope lookup, used by py_register_def at registry-build time. Bare class names are qualified to <module_qn>.<name> so registry lookups match. - py_register_def prefers d->return_type (full subscripted text) over d->return_types[0] when brackets are present — extract_defs's array form strips the subscript, losing element types like Optional[Foo]. Narrowing: - if isinstance(x, T): bind x as NAMED(T) inside the consequence body (block-scoped via push/pop). - if x is not None: strip None from x's UNION inside the consequence; py_match_is_none recognizes "is not" as the single tree-sitter token it actually is, walks through parens / walrus to find the underlying identifier. - Else branch unchanged — narrow's negation (not-T, including-None) is not modeled in v1. Walrus + truthy: - if (x := compute()) is not None: walrus binds x in the enclosing scope (PEP 572) so the body sees x. py_bind_walrus_in walks the cond AST looking for named_expression / assignment_expression nodes. Comprehension + for-loop element typing: - New py_iterable_element_type maps TEMPLATE(list/set/Iterable/...) to arg[0]; TEMPLATE(dict) to key arg; TEMPLATE(tuple, ...) to UNION of args. - Comprehensions push their own scope and bind for_in_clause loop vars to the iterable's element type before walking body / filter clauses. for_statement does the same. UNION attribute access fallback (used when narrowing can't run): - obj_type=UNION & exactly one non-None NAMED member has the attr: emit edge with strategy=lsp_method_union, confidence 0.85. 7 new test_py_lsp.c cases. All 2880 prior tests stay green; 8 new tests land. Bench unchanged (small fixture, no narrowing exercised there).