@@ -1922,31 +1922,34 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
19221922 return None
19231923 else :
19241924 assert isinstance (exc_value , NameError )
1925- # find most recent frame
1926- if tb is None :
1925+ try :
1926+ # find most recent frame
1927+ if tb is None :
1928+ return None
1929+ while tb .tb_next is not None :
1930+ tb = tb .tb_next
1931+ frame = tb .tb_frame
1932+ d = (
1933+ list (frame .f_locals )
1934+ + list (frame .f_globals )
1935+ + list (frame .f_builtins )
1936+ )
1937+ d = [x for x in d if isinstance (x , str )]
1938+ if not_normalized and wrong_name in d :
1939+ return wrong_name
1940+
1941+ # Check first if we are in a method and the instance
1942+ # has the wrong name as attribute
1943+ if 'self' in frame .f_locals :
1944+ self = frame .f_locals ['self' ]
1945+ try :
1946+ has_wrong_name = hasattr (self , wrong_name )
1947+ except Exception :
1948+ has_wrong_name = False
1949+ if has_wrong_name :
1950+ return f"self.{ wrong_name } "
1951+ except Exception :
19271952 return None
1928- while tb .tb_next is not None :
1929- tb = tb .tb_next
1930- frame = tb .tb_frame
1931- d = (
1932- list (frame .f_locals )
1933- + list (frame .f_globals )
1934- + list (frame .f_builtins )
1935- )
1936- d = [x for x in d if isinstance (x , str )]
1937- if not_normalized and wrong_name in d :
1938- return wrong_name
1939-
1940- # Check first if we are in a method and the instance
1941- # has the wrong name as attribute
1942- if 'self' in frame .f_locals :
1943- self = frame .f_locals ['self' ]
1944- try :
1945- has_wrong_name = hasattr (self , wrong_name )
1946- except Exception :
1947- has_wrong_name = False
1948- if has_wrong_name :
1949- return f"self.{ wrong_name } "
19501953
19511954 if not_normalized and wrong_name in d :
19521955 return wrong_name
0 commit comments