Skip to content

TypedPython step 1: soundness gate - #19

Merged
b-re-w merged 4 commits into
developfrom
work/typedpython-gate
Oct 3, 2026
Merged

b-re-w merged 4 commits into
developfrom
work/typedpython-gate

Conversation

@b-re-w

@b-re-w b-re-w commented Oct 2, 2026

Copy link
Copy Markdown
Member

Closes #16

Feature added

  • python -m typedpython check [--mode checked|compiled] [--format text|json] [--search-path DIR] PATHS... in python-multiplatform-ksp/src/main/python/typedpython/.
    • Pyrefly 1.3.2 (pinned) runs with its six Any-leak kinds raised to error.
    • any-flow: any user-code expression whose type is Any/Unknown is an error. This comes from Pyrefly's per-expression type report. Three cases are excluded: cast() arguments, values discarded by an expression statement, and callable signatures.
    • The forbidden list (eval/exec, getattr/setattr/delattr with a computed name, patching an imported module or a module-level class) is a warning in checked and an error in compiled.
    • Nothing inside dependencies is reported. Exit codes: 0 clean, 1 errors, 2 tool failure.

Test added

29 tests in python-multiplatform-ksp/src/test/python/, including one measurement test.
Run: python-multiplatform-ksp/.venv/bin/python -m pytest from python-multiplatform-ksp/ (venv: uv venv .venv && uv pip install --python .venv/bin/python pyrefly==1.3.2 pytest).

  • Red (before implementation, against an API skeleton): 29 failed. Every failure was NotImplementedError: 11 from forbidden.scan, 13 from gate.check, 5 from the CLI.
  • Green: 29 passed.
  • Mutation check (AGENTS.md §8): I disabled each new path and checked that tests fail.
    • any-flow off: 1 failed
    • raised kinds removed: 7 failed
    • mode ignored: 2 failed
    • restored: all pass

Documentation corrected

  • docs/INTENT.md §1 adds purpose 4, TypedPython, with the maintainer's statements quoted. The "not a transpiler" row now says that compiled code is a CPython extension module.
  • docs/SPEC.md adds N-6, marked partial.
  • docs/design/typedpython.md adds §6.1, the current state of step 1.

Not done (named in SPEC N-6)

  • The build does not run the gate yet. That is step 1b, a Gradle task, and it will be coordinated with the PMM build supporter.
  • Rebinding a variable to a different type, and containers with mixed element types, are not detected. Pyrefly 1.3.2 reports neither.
  • Measured cost: about 8× a plain pyrefly check on a synthetic 1800-line module (160–235 ms → 1.3–1.9 s). The machine was under load, so read the ratio, not the absolute numbers. To be reduced before 1b.

b-re-w added 2 commits October 3, 2026 07:04
Step 1 of docs/design/typedpython.md: python -m typedpython check runs Pyrefly
with its Any-leak kinds raised to errors, reports user-code expressions of type
Any outside cast() (any-flow), and reports the forbidden list as warnings in
checked mode and errors in compiled mode. Lives in python-multiplatform-ksp.

INTENT gains TypedPython as purpose 4 (maintainer statements quoted); SPEC
gains N-6 (partial: not yet run by the build).

Refs #16
toolchain installs the gate with uv at a pinned version (1b, #20), so the
package needs a build backend and a console script. Wheel built and smoke-
tested: installed from --find-links, typedpython check exits 0 on clean code
and 1 on an unannotated function.

Refs #16
The gate's Pyrefly config lives in a temporary directory, which Pyrefly took
as the import root, so relative and absolute self-imports of user packages did
not resolve and every value from them failed as any-flow. Each checked file's
import root (above its outermost package) now goes on the search path.

Red before the fix: 3 failed in test_imports.py.

Refs #16
A directory argument crashed with IsADirectoryError (found by the toolchain
typedpythonCheck work). Directories now expand to their .py files, skipping
hidden directories, __pycache__ and build.

Red before the fix: test_a_directory_is_checked_file_by_file.

Refs #16
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