Skip to content

TypedPython gate: one Pyrefly run per check - #52

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

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

Conversation

@b-re-w

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

Copy link
Copy Markdown
Member

Refs #21. This does not close it: the issue's done criterion is a cost of at most 2× plain pyrefly check, measured on an idle machine, and that measurement has not been possible yet.

Stacked on #33 → #19. This PR's own change is the last commit, 4f99132.

Feature added

Pyrefly now runs once per gate check, including when a file needs probing.

  • When probing is needed, every file in the check is mirrored, and Pyrefly runs on the copies.
  • _Remap maps error and any-flow positions back to the original columns.
  • An error located inside an inserted probe is reported as internal/probe-error instead of being dropped.
  • any-flow is computed on the probed text's AST, so the probe loads are never reported.

Test added

  • test_pyrefly_runs_once_when_a_file_has_a_candidate: red against the old gate (2 runs).
  • Column-remap tests, for an error left of a probe and an error right of a probe.

Results:

  • Mutation: removing the column shift makes the remap test fail ((3, 15) != (3, 12)).
  • Green: 50 passed on this branch, re-run by the coordinating session.

Measurement (not valid)

  • Cost relative to plain pyrefly check: 7.6×, previously 15×.
  • Load averages were 30–43 during the run, so the ratio is not reliable either.

b-re-w added 7 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
Pyrefly 1.3.2 reports neither and records no types for assignment targets,
but it does record the type of every name load. The gate now writes a probed
copy in which each candidate assignment is followed on the same line by a
load of its targets (line numbers unchanged), runs Pyrefly on it, and judges
the types at the probe positions. The second run happens only when a file
assigns a name twice or has a container display.

Refs #22
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 probed copy written alone into a temporary directory lost its package, so
relative imports in it did not resolve, their values were Unknown, and
rebinding went unreported in exactly the code that lives in packages. The
probe pass now copies each file's package tree with the same layout.

Red before the fix: test_rebinding_inside_a_package_with_relative_imports.

Refs #22
When a file needs probing, every file of the check is mirrored and Pyrefly
runs once on the copies; errors and any-flow positions are mapped back to the
original columns (_Remap), and an error inside an inserted probe surfaces as
internal/probe-error instead of being dropped.

Red: test_pyrefly_runs_once_when_a_file_has_a_candidate (2 runs). Mutation:
removing the column shift fails the remap test.

Refs #21
@b-re-w
b-re-w merged commit b4688c8 into develop Oct 3, 2026
@b-re-w
b-re-w deleted the work/typedpython-gate-once branch October 3, 2026 10:13
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