Accept single-edit typos in correction gates

difflib's SequenceMatcher underrates adjacent transpositions, so the
flagship examples (gti->git 0.667, greo->grep 0.75, psuh->push 0.75)
fell below the 0.8 ratio gates and were declined. Per the plan
amendment, the token and candidate gates in the history resolver,
guess_from_path and the help resolver additionally accept a
first-char-equal single edit (one substitution, insertion, deletion
or adjacent transposition; new thefuck/typo.py), with the ratio
cutoffs, the exact-one-candidate rule and the 0.79 boundary (edit
distance >= 2) unchanged.
This commit is contained in:
Alexander
2026-09-13 21:00:20 +02:00
parent 572d301bfe
commit 8d2f2fa11c
8 changed files with 218 additions and 26 deletions
+17 -1
View File
@@ -10,7 +10,7 @@ import time
import pytest
from thefuck import shell_ast
from thefuck import shell_ast, typo
from thefuck.resolvers.help_resolver import get_help_correction
@@ -95,6 +95,22 @@ def test_returns_correction_when_subcommand_misspelled(
assert _spawned(argv_log) == ['--help']
def test_corrects_transposed_subcommand(fake_bin, argv_log, enable_cache):
# bulid -> build scores 2 * 4 / 10 = 0.8, right at the cutoff,
# and is also a single transposition (li <-> il).
fake_bin('fake')
assert get_help_correction('fake bulid .') == 'fake build .'
assert typo.single_edit('bulid', 'build')
def test_corrects_transposition_under_cutoff(
fake_bin, argv_log, enable_cache):
# psuh -> push scores 2 * 3 / 8 = 0.75, under the cutoff, so only
# the first-char-equal single-edit match fixes it.
fake_bin('fake', commands=('push', 'build', 'clean'))
assert get_help_correction('fake psuh x') == 'fake push x'
def test_respawns_when_binary_mtime_changes(
fake_bin, argv_log, enable_cache):
path = fake_bin('fake')