Repository navigation
TypedPython gate: one Pyrefly run per check - #52
Merged
Merged
Conversation
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
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
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.
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.
_Remapmaps error andany-flowpositions back to the original columns.internal/probe-errorinstead of being dropped.any-flowis 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).Results:
(3, 15) != (3, 12)).Measurement (not valid)
pyrefly check: 7.6×, previously 15×.