Skip to content

native: annotate module-level values; discarded matches run in place - #166

Merged
simontreanor merged 1 commit into
mainfrom
native-module-value-annotations
Sep 28, 2026
Merged

simontreanor merged 1 commit into
mainfrom
native-module-value-annotations

Conversation

@simontreanor

Copy link
Copy Markdown
Owner

mypyc's front end rejected two shapes that a real multi-module program produces. This fixes both.

  • Module-level values that another module reads failed with "Cannot determine type". Native mode now writes the type down:
    • _X: X = X() for a nullary singleton;
    • the inferred type on the first assignment of a top-level value that's bound once, when Python can spell it.
  • A unit match in statement position was hoisted into a temp that only ever received unit calls, and mypyc rejected it with "has inferred type None". The arms now evaluate in place.

With both fixes, a real multi-module program gets through mypyc's type checking locally. It stops only at build_ext on a machine without a C compiler.

Tests: native_annotates_module_level_values_for_other_modules and native_evaluates_a_discarded_match_in_place. ROADMAP and INTERNALS are updated.

mypyc's front end rejected two shapes a real multi-module program produces:

- A module-level value another module reads ("Cannot determine type").
  Native mode now writes the type down: `_X: X = X()` for a nullary
  singleton, and the inferred type on the first assignment of a
  top-level value bound once, when Python can spell it.
- A unit match in statement position, hoisted into a temp that is only
  ever assigned unit calls ("has inferred type None"). The arms now
  evaluate in place.
@simontreanor
simontreanor merged commit 2b83615 into main Sep 28, 2026
20 checks passed
@simontreanor
simontreanor deleted the native-module-value-annotations branch September 28, 2026 09:03
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