Interactive mode: an answer applies to one occurrence, not the whole run - #3990
Open
Eljees wants to merge 1 commit into
Open
Interactive mode: an answer applies to one occurrence, not the whole run#3990Eljees wants to merge 1 commit into
Eljees wants to merge 1 commit into
Conversation
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.
Fixes #62.
The root cause is that
ask_for_word_fixanswers a question about one occurrence by mutating the sharedMisspellingobject, so a single answer leaks into every later occurrence of the word in the run. Observed on currentmaster(all transcripts scripted, answers fed on stdin):-w -i 1, the same word in two files, answersn,y: the second file never asks — the rejection turned the word off globally, and the queuedyis never consumed.-w -i 3, reject a word, then meet it in the next file: the prompt degrades from(Y/n)toChoose an option (blank for none): 0) ...— the "handled as a list of available fixes" behaviour from the issue, still alive.-w -i 2, a word with a single candidate, answer blank ("blank for none"): the file is changed anyway —FIXED: c.txt.Three changes:
ask_for_word_fixno longer mutatesmisspelling; it returns the answer for this occurrence.asked_forbecomes a dict and moves out of the per-line scope, where its reset meant "asked once per file" only held because of the mutation). Accepting and rejecting now behave symmetrically: each word is asked once per file, and the answer covers the rest of that file.--helpsays level 2 is for ("ask user to choose one fix when more than one is available"). Single-candidate words at-i 2are written without a prompt, as documented; the blank-accepts-anyway path is gone.These are the first tests for interactive mode in the suite; they feed answers through stdin. On the unpatched tree the three bug tests fail exactly on the behaviours above, the per-file control passes; with the fix all four pass. Full
test_basic.py: 86 passed, 3 failed — the same three failures (chardet import) as on a clean tree.ruff check,ruff format --checkclean; mypy reports the same two pre-existing errors as on a clean tree.AI-assisted (LLM used for drafting); the runs above are mine.