Repository navigation
TypedPython step 1: soundness gate (Any leaks become errors) #16
Description
What
Step 1 of TypedPython (docs/design/typedpython.md §4.2, §6): a soundness gate that turns the places where Any leaks into user Python code into errors, and reports the §3.1 forbidden list.
- Type checking is delegated to Pyrefly (pinned 1.3.2), run as a CLI with a generated config.
- The
Any-leak error kinds Pyrefly already has are raised toerror:implicit-any-parameter,unannotated-return,unknown-variable-type,no-any-return-implicit,no-any-return-explicit,explicit-any. any-flow: an expression in user code whose inferred type isAny/Unknown(for example, the result of an untyped dependency) is an error, unless it sits insidetyping.cast(...). Read from Pyrefly's per-expression type report (--report-pysa).- Forbidden list, by Python
ast:eval/exec,getattr/setattr/delattrwith a non-literal name, and monkeypatching (assigning or deleting attributes on an imported module or a module-level class). These are warnings incheckedmode, the default, and errors incompiledmode (design §8 item 7 is still open, so this is a switch). - Third-party code is not checked. Only the files you pass in are checked.
- CLI:
python -m typedpython check [--mode checked|compiled] [--format text|json] [--search-path DIR] PATHS.... Exit code 0 means no errors, 1 means errors, 2 means the tool failed.
Why
TypedPython is to be PythonMultiplatform's default behaviour: user code is always checked, and compilation is opt-in (maintainer decision, 2026-10-02). The gate is the base that both the build step (1b) and the compiler (step 2) stand on.
Where
Inside the KSP module: python-multiplatform-ksp/src/main/python/typedpython/, with tests in python-multiplatform-ksp/src/test/python/, following the maintainer's direction ("ksp랑 통합"). Nothing is added at the repository root. Wiring it into Gradle (bundling it into the jar, running it during the build) is step 1b. That overlaps with the PMM build supporter, so it is settled with them before it starts.
Not in this step
- Detecting a variable being reassigned to a different type, and containers with mixed element types. Pyrefly 1.3.2 does not report either, and its per-expression type report has no entries for assignment targets. These become a follow-up issue.
- Any change to Gradle or Kotlin.
Done when
python-multiplatform-ksp/.venv/bin/python -m pytest python-multiplatform-ksp/src/test/python passes, and the red output from before the implementation is recorded in the PR:
- each Pyrefly
Any-leak kind fails the gate any-flowis reported for an untyped dependency's result, and not when it is wrapped incast- each forbidden-list rule is a warning under
checkedand an error undercompiled, and literal-namegetattrandself.x = ...are not flagged - the CLI's exit codes are 0, 1 and 2
- a measurement test records the gate's time next to a plain
pyrefly checkon a synthetic module
Activity
Build: Package the TypedPython gate as a typedpython wheel
Fix: Resolve a package's own imports in the gate
Fix: Accept directories in typedpython check
b-re-w commentedon Oct 3, 2026
Landed in develop via #64 (which carried the stacked PR for this issue).