@@ -1485,11 +1485,22 @@ def _find_keyword_typos(self):
14851485 # Limit the number of possible matches to try
14861486 max_matches = 3
14871487 matches = []
1488+
1489+ hint = _get_cross_language_keyword_hint (wrong_name )
1490+ if hint :
1491+ matches .append (hint )
14881492 if _suggestions is not None :
1489- suggestion = _suggestions ._generate_suggestions (keyword .kwlist , wrong_name )
1493+ suggestion = _suggestions ._generate_suggestions (keyword .kwlist + keyword . softkwlist , wrong_name )
14901494 if suggestion :
14911495 matches .append (suggestion )
1492- matches .extend (difflib .get_close_matches (wrong_name , keyword .kwlist , n = max_matches , cutoff = 0.5 ))
1496+ matches .extend (
1497+ difflib .get_close_matches (
1498+ wrong_name ,
1499+ keyword .kwlist + keyword .softkwlist ,
1500+ n = max_matches ,
1501+ cutoff = 0.5
1502+ )
1503+ )
14931504 matches = matches [:max_matches ]
14941505 for suggestion in matches :
14951506 if not suggestion or suggestion == wrong_name :
@@ -1787,6 +1798,17 @@ def print(self, *, file=None, chain=True, **kwargs):
17871798})
17881799
17891800
1801+ # Cross-language keyword suggestions.
1802+ _CROSS_LANGUAGE_KEYWORD_HINTS = frozendict ({
1803+ # C/C++ equivalents
1804+ 'switch' : 'match' ,
1805+ 'delete' : 'del' ,
1806+ # function define equivalents
1807+ 'function' : 'def' ,
1808+ 'func' : 'def' ,
1809+ 'void' : 'def' ,
1810+ })
1811+
17901812def _substitution_cost (ch_a , ch_b ):
17911813 if ch_a == ch_b :
17921814 return 0
@@ -1866,6 +1888,12 @@ def _get_cross_language_hint(obj, wrong_name):
18661888 return None
18671889
18681890
1891+ def _get_cross_language_keyword_hint (wrong_name ):
1892+ """Check if wrong_name is a common keyword from another language
1893+ """
1894+ return _CROSS_LANGUAGE_KEYWORD_HINTS .get (wrong_name )
1895+
1896+
18691897def _get_safe___dir__ (obj ):
18701898 # Use obj.__dir__() to avoid a TypeError when calling dir(obj).
18711899 # See gh-131001 and gh-139933.
0 commit comments