You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Treat swapped adjacent letters as a single edit in "Did you mean" suggestions #161498
Name suggestions use a Levenshtein distance without transpositions, so swapping two adjacent letters costs two substitutions (4). This misses very common typos, and sometimes suggests an unrelated name instead:
>>> Ture
NameError: name 'Ture' is not defined
>>> compelx
NameError: name 'compelx' is not defined. Did you mean: 'compile'?
I propose counting a swap of two adjacent characters as one edit (cost 2, like a substitution), i.e. the optimal string alignment distance. Thresholds stay the same.
If this sounds reasonable, I'd be happy to open a PR.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
So your description isn't right, is it? Transpositions are already handled like you want. Do you want to change your proposal to making "Did you mean" case insensitive?
Sorry, the example I gave in the description seem wasn't good—it involved both swapping two letters and changing case, two kinds of transformations. I'll revise my description. Ture is a good example. When I type Ture, it doesn't ask me whether I meant to type True; it just shows NameError: name 'Ture' is not defined.
In the current implementation, whether NameError: name 'A' is not defined. Did you mean: 'B'? is displayed is determined by whether the cost of turning A into B is less than a threshold. Changing case costs 1, changing a character costs 2. Swapping two characters means changing two characters, which costs 4, whereas my idea is to count swapping two characters as a single operation costing 2
I think reversing the order of two letters in a word is an action with a probability similar to that of missing or adding an extra letter, so their costs should also be the same
changed the title [-]Count adjacent transpositions in "Did you mean" suggestions[/-][+]Treat swapped adjacent letters as a single edit in "Did you mean" suggestions[/+]on Nov 7, 2026
Activity
picnixz commentedon Nov 6, 2026
cc @pablogsal @johnslavik
pochmann commentedon Nov 7, 2026
For
FlaseI already get:moontc commentedon Nov 7, 2026
@pochmann thanks for checking, but in my description, I wrote
flase, instead ofFlaseture->tupleTure-> no suggestionflase-> no suggestionFlase->False(it's correct)pochmann commentedon Nov 7, 2026
Yes, I know you did.
So your description isn't right, is it? Transpositions are already handled like you want. Do you want to change your proposal to making "Did you mean" case insensitive?
moontc commentedon Nov 7, 2026
Sorry, the example I gave in the description seem wasn't good—it involved both swapping two letters and changing case, two kinds of transformations. I'll revise my description.
Tureis a good example. When I typeTure, it doesn't ask me whether I meant to typeTrue; it just showsNameError: name 'Ture' is not defined.In the current implementation, whether
NameError: name 'A' is not defined. Did you mean: 'B'?is displayed is determined by whether the cost of turning A into B is less than a threshold. Changing case costs 1, changing a character costs 2. Swapping two characters means changing two characters, which costs 4, whereas my idea is to count swapping two characters as a single operation costing 2I think reversing the order of two letters in a word is an action with a probability similar to that of missing or adding an extra letter, so their costs should also be the same
[-]Count adjacent transpositions in "Did you mean" suggestions[/-][+]Treat swapped adjacent letters as a single edit in "Did you mean" suggestions[/+]