Repository navigation
native: annotate local functions; a real program through mypy - #163
Merged
Merged
Conversation
Functions defined inside functions are annotated in native mode as they lower (lower_binding_as has the binding and its type), with the user-type spellings computed up front. Unit results are left unannotated, since mypy rejects returning a unit call's value under -> None. In a native project the shared runtime's data class fields say Any too. pyfun build passes mypyc three more flags that disable error codes restating the Python boundary (func-returns-value, var-annotated, union-attr). With these, the native output of the 11-module Scrabble game passes mypy's front end (64 errors to 0) and its replays print the same. mypyc itself stops on module-level values another module reads at import time, recorded in ROADMAP as the next blocker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Takes
--nativefurther toward a real program, using the private Scrabble game (locally only; the game repo is untouched and nothing of it goes to CI) as the audit.Changes
lower_binding_ashas the binding, its span and so its type. User-type spellings are computed up front (native_type_spellings) andtyped_signatureis shared with the top-level pass.return sys.stdout.flush()), which mypy rejects under-> None._pyfun_rt.py) getsAnyfields too (runtime_module_native). Without it, everyOptionpayload arrived typedobject.pyfun buildalso disables three mypy error codes that only restate the Python boundary:func-returns-value(_ = f(x)for unit calls),var-annotatedandunion-attr(module-level values mypy can't infer, typeshed unions atexterncalls). The extern declarations are the contract there, and Pyfun's checker has already enforced them.The audit: the game's native output went from 64 mypy errors to 0 (12 files), and all 5 recorded replays print identically in both builds. mypyc itself then stops on Cannot determine type for module-level values another module reads at import time (nullary singletons like
board._QW, layout tables), even though plain mypy is happy. That's recorded in ROADMAP as the next native blocker.Test:
native_annotates_block_local_functions_and_leaves_unit_returns_bare. DESIGN §5.6 and ROADMAP updated.