Add --dry-run flag to pyrefly infer#3991
Open
nitishagar wants to merge 1 commit into
Open
Conversation
Summary: pyrefly infer rewrites files in place and always exits 0, so it cannot be used as a CI check for whether the formatter would make changes. Add a --dry-run flag that runs the full inference, prints what changes would be made, writes nothing, and exits 1 if any file would change else 0. The change set is already computed by the existing read-only phase of run_inner; dry-run simply skips the two file writes (gated on a new dry_run flag on InferFlags), logs the planned changes per file, and returns UserError when any changes are pending. Non-dry-run behavior is unchanged. Fixes facebook#3920 Test Plan: cargo build -p pyrefly; cargo test -p pyrefly dry_run (12 passed); cargo clippy -p pyrefly --tests; manual - pyrefly infer --dry-run on an unannotated file leaves it unchanged and exits 1 with the planned change printed; without --dry-run the file is annotated and exits 0.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Summary
pyrefly inferrewrites files in place and always exits 0, so it cannot be used as a CI check for whether the formatter would make any changes.This adds a
--dry-runflag topyrefly inferthat runs the full inference, prints what changes would be made, writes nothing, and exits0if no changes would be made or1if any changes would be made — enabling CI check mode.The change set is already computed by the existing read-only phase of
run_inner; dry-run simply skips the two file writes (gated on a newdry_runflag onInferFlags), logs the planned changes per file, and returnsUserErrorwhen any changes are pending. Non-dry-run behavior is unchanged.Fixes #3920.
Test plan
cargo build -p pyreflycargo test -p pyrefly dry_run— 12 passed, asserting both the exit status (UserErrorwhen changes,Successwhen none) and that the file is left byte-identical.cargo clippy -p pyrefly --testspyrefly infer --dry-runon an unannotated file leaves it unchanged and exits 1 with the planned change printed; without--dry-runthe file is annotated and exits 0.