@@ -1954,31 +1954,34 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
19541954 return None
19551955 else :
19561956 assert isinstance (exc_value , NameError )
1957- # find most recent frame
1958- if tb is None :
1957+ try :
1958+ # find most recent frame
1959+ if tb is None :
1960+ return None
1961+ while tb .tb_next is not None :
1962+ tb = tb .tb_next
1963+ frame = tb .tb_frame
1964+ d = (
1965+ list (frame .f_locals )
1966+ + list (frame .f_globals )
1967+ + list (frame .f_builtins )
1968+ )
1969+ d = [x for x in d if isinstance (x , str )]
1970+ if not_normalized and wrong_name in d :
1971+ return wrong_name
1972+
1973+ # Check first if we are in a method and the instance
1974+ # has the wrong name as attribute
1975+ if 'self' in frame .f_locals :
1976+ self = frame .f_locals ['self' ]
1977+ try :
1978+ has_wrong_name = hasattr (self , wrong_name )
1979+ except Exception :
1980+ has_wrong_name = False
1981+ if has_wrong_name :
1982+ return f"self.{ wrong_name } "
1983+ except Exception :
19591984 return None
1960- while tb .tb_next is not None :
1961- tb = tb .tb_next
1962- frame = tb .tb_frame
1963- d = (
1964- list (frame .f_locals )
1965- + list (frame .f_globals )
1966- + list (frame .f_builtins )
1967- )
1968- d = [x for x in d if isinstance (x , str )]
1969- if not_normalized and wrong_name in d :
1970- return wrong_name
1971-
1972- # Check first if we are in a method and the instance
1973- # has the wrong name as attribute
1974- if 'self' in frame .f_locals :
1975- self = frame .f_locals ['self' ]
1976- try :
1977- has_wrong_name = hasattr (self , wrong_name )
1978- except Exception :
1979- has_wrong_name = False
1980- if has_wrong_name :
1981- return f"self.{ wrong_name } "
19821985
19831986 if not_normalized and wrong_name in d :
19841987 return wrong_name
0 commit comments