Skip to content

Interactive mode: an answer applies to one occurrence, not the whole run - #3990

Open
Eljees wants to merge 1 commit into
codespell-project:mainfrom
Eljees:fix/62-interactive-answer-scope
Open

Interactive mode: an answer applies to one occurrence, not the whole run#3990
Eljees wants to merge 1 commit into
codespell-project:mainfrom
Eljees:fix/62-interactive-answer-scope

Conversation

@Eljees

@Eljees Eljees commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #62.

The root cause is that ask_for_word_fix answers a question about one occurrence by mutating the shared Misspelling object, so a single answer leaks into every later occurrence of the word in the run. Observed on current master (all transcripts scripted, answers fed on stdin):

  • -w -i 1, the same word in two files, answers n, y: the second file never asks — the rejection turned the word off globally, and the queued y is never consumed.
  • -w -i 3, reject a word, then meet it in the next file: the prompt degrades from (Y/n) to Choose 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:

  1. ask_for_word_fix no longer mutates misspelling; it returns the answer for this occurrence.
  2. The caller remembers answers per word per file (asked_for becomes 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.
  3. The option-list branch now triggers only for words with more than one candidate, which is what --help says level 2 is for ("ask user to choose one fix when more than one is available"). Single-candidate words at -i 2 are 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 --check clean; mypy reports the same two pre-existing errors as on a clean tree.

AI-assisted (LLM used for drafting); the runs above are mine.

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.

Interactive lvl 1 has undesired behavior

1 participant