@@ -1485,18 +1485,19 @@ 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 + keyword .softkwlist + [ 'switch' ] , wrong_name )
1493+ suggestion = _suggestions ._generate_suggestions (keyword .kwlist + keyword .softkwlist , wrong_name )
14901494 if suggestion :
14911495 matches .append (suggestion )
14921496 matches .extend (difflib .get_close_matches (wrong_name , keyword .kwlist , n = max_matches , cutoff = 0.5 ))
14931497 matches = matches [:max_matches ]
14941498 for suggestion in matches :
14951499 if not suggestion or suggestion == wrong_name :
14961500 continue
1497- # semantic edge case
1498- if suggestion == 'switch' or wrong_name == 'switch' :
1499- suggestion = 'match'
15001501 # Try to replace the token with the keyword
15011502 the_lines = error_lines .copy ()
15021503 the_line = the_lines [start [0 ] - 1 ][:]
@@ -1790,6 +1791,20 @@ def print(self, *, file=None, chain=True, **kwargs):
17901791})
17911792
17921793
1794+ # Cross-language keyword suggestions.
1795+ _CROSS_LANGUAGE_KEYWORD_HINTS = frozendict ({
1796+ # C/C++ equivalents
1797+ 'switch' : 'match' ,
1798+ 'delete' : 'del' ,
1799+ # function define equivalents
1800+ 'function' : 'def' ,
1801+ 'func' : 'def' ,
1802+ # null equivalents
1803+ 'NULL' : 'None' ,
1804+ 'null' : 'None' ,
1805+ 'nil' : 'None' ,
1806+ })
1807+
17931808def _substitution_cost (ch_a , ch_b ):
17941809 if ch_a == ch_b :
17951810 return 0
@@ -1869,6 +1884,13 @@ def _get_cross_language_hint(obj, wrong_name):
18691884 return None
18701885
18711886
1887+ def _get_cross_language_keyword_hint (wrong_name ):
1888+ """Check if wrong_name is a common keyword from another language
1889+ """
1890+ hint = _CROSS_LANGUAGE_KEYWORD_HINTS .get (wrong_name )
1891+ return hint
1892+
1893+
18721894def _get_safe___dir__ (obj ):
18731895 # Use obj.__dir__() to avoid a TypeError when calling dir(obj).
18741896 # See gh-131001 and gh-139933.
0 commit comments