Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 32c4bbe

Browse filesBrowse files
authored
gh-132449: Improve the algorithm to detect typos in keywords (#132837)
1 parent 85f89cb commit 32c4bbe
Copy full SHA for 32c4bbe

File tree

Expand file treeCollapse file tree

2 files changed

+13
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-3
lines changed

‎Lib/test/test_syntax.py

Copy file name to clipboardExpand all lines: Lib/test/test_syntax.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,12 @@
18381838
Traceback (most recent call last):
18391839
SyntaxError: invalid syntax. Did you mean 'for'?
18401840
1841+
1842+
>>> for x im n:
1843+
... pass
1844+
Traceback (most recent call last):
1845+
SyntaxError: invalid syntax. Did you mean 'in'?
1846+
18411847
>>> f(a=23, a=234)
18421848
Traceback (most recent call last):
18431849
...

‎Lib/traceback.py

Copy file name to clipboardExpand all lines: Lib/traceback.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,10 +1339,14 @@ def _find_keyword_typos(self):
13391339
if tokens_left_to_process < 0:
13401340
break
13411341
# Limit the number of possible matches to try
1342-
matches = difflib.get_close_matches(wrong_name, keyword.kwlist, n=3)
1343-
if not matches and _suggestions is not None:
1342+
max_matches = 3
1343+
matches = []
1344+
if _suggestions is not None:
13441345
suggestion = _suggestions._generate_suggestions(keyword.kwlist, wrong_name)
1345-
matches = [suggestion] if suggestion is not None else matches
1346+
if suggestion:
1347+
matches.append(suggestion)
1348+
matches.extend(difflib.get_close_matches(wrong_name, keyword.kwlist, n=max_matches, cutoff=0.5))
1349+
matches = matches[:max_matches]
13461350
for suggestion in matches:
13471351
if not suggestion or suggestion == wrong_name:
13481352
continue

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.