Skip to content

TypedPython step 1: soundness gate (Any leaks become errors) #16

Closed

Description

@b-re-w

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 to error: 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 is Any/Unknown (for example, the result of an untyped dependency) is an error, unless it sits inside typing.cast(...). Read from Pyrefly's per-expression type report (--report-pysa).
  • Forbidden list, by Python ast: eval/exec, getattr/setattr/delattr with a non-literal name, and monkeypatching (assigning or deleting attributes on an imported module or a module-level class). These are warnings in checked mode, the default, and errors in compiled mode (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-flow is reported for an untyped dependency's result, and not when it is wrapped in cast
  • each forbidden-list rule is a warning under checked and an error under compiled, and literal-name getattr and self.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 check on a synthetic module

Activity

  1. b-re-w commented on Oct 3, 2026

    @b-re-w
    MemberAuthor

    Landed in develop via #64 (which carried the stacked PR for this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions