@@ -1111,7 +1111,10 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
11111111 wrong_name = getattr (exc_value , "name_from" , None )
11121112 suggestion = _compute_suggestion_error (exc_value , exc_traceback , wrong_name )
11131113 if suggestion :
1114- self ._str += f". Did you mean: '{ suggestion } '?"
1114+ if suggestion .isascii ():
1115+ self ._str += f". Did you mean: '{ suggestion } '?"
1116+ else :
1117+ self ._str += f". Did you mean: '{ suggestion } ' ({ suggestion !a} )?"
11151118 elif exc_type and issubclass (exc_type , ModuleNotFoundError ):
11161119 module_name = getattr (exc_value , "name" , None )
11171120 if module_name in sys .stdlib_module_names :
@@ -1129,7 +1132,10 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
11291132 wrong_name = getattr (exc_value , "name" , None )
11301133 suggestion = _compute_suggestion_error (exc_value , exc_traceback , wrong_name )
11311134 if suggestion :
1132- self ._str += f". Did you mean: '{ suggestion } '?"
1135+ if suggestion .isascii ():
1136+ self ._str += f". Did you mean: '{ suggestion } '?"
1137+ else :
1138+ self ._str += f". Did you mean: '{ suggestion } ' ({ suggestion !a} )?"
11331139 if issubclass (exc_type , NameError ):
11341140 wrong_name = getattr (exc_value , "name" , None )
11351141 if wrong_name is not None and wrong_name in sys .stdlib_module_names :
@@ -1654,6 +1660,13 @@ def _check_for_nested_attribute(obj, wrong_name, attrs):
16541660def _compute_suggestion_error (exc_value , tb , wrong_name ):
16551661 if wrong_name is None or not isinstance (wrong_name , str ):
16561662 return None
1663+ not_normalized = False
1664+ if not wrong_name .isascii ():
1665+ from unicodedata import normalize
1666+ normalized_name = normalize ('NFKC' , wrong_name )
1667+ if normalized_name != wrong_name :
1668+ not_normalized = True
1669+ wrong_name = normalized_name
16571670 if isinstance (exc_value , AttributeError ):
16581671 obj = exc_value .obj
16591672 try :
@@ -1699,6 +1712,8 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
16991712 + list (frame .f_builtins )
17001713 )
17011714 d = [x for x in d if isinstance (x , str )]
1715+ if not_normalized and wrong_name in d :
1716+ return wrong_name
17021717
17031718 # Check first if we are in a method and the instance
17041719 # has the wrong name as attribute
@@ -1711,6 +1726,8 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
17111726 if has_wrong_name :
17121727 return f"self.{ wrong_name } "
17131728
1729+ if not_normalized and wrong_name in d :
1730+ return wrong_name
17141731 try :
17151732 import _suggestions
17161733 except ImportError :
0 commit comments