@@ -1626,29 +1626,32 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
16261626 return None
16271627 else :
16281628 assert isinstance (exc_value , NameError )
1629- # find most recent frame
1630- if tb is None :
1629+ try :
1630+ # find most recent frame
1631+ if tb is None :
1632+ return None
1633+ while tb .tb_next is not None :
1634+ tb = tb .tb_next
1635+ frame = tb .tb_frame
1636+ d = (
1637+ list (frame .f_locals )
1638+ + list (frame .f_globals )
1639+ + list (frame .f_builtins )
1640+ )
1641+ d = [x for x in d if isinstance (x , str )]
1642+
1643+ # Check first if we are in a method and the instance
1644+ # has the wrong name as attribute
1645+ if 'self' in frame .f_locals :
1646+ self = frame .f_locals ['self' ]
1647+ try :
1648+ has_wrong_name = hasattr (self , wrong_name )
1649+ except Exception :
1650+ has_wrong_name = False
1651+ if has_wrong_name :
1652+ return f"self.{ wrong_name } "
1653+ except Exception :
16311654 return None
1632- while tb .tb_next is not None :
1633- tb = tb .tb_next
1634- frame = tb .tb_frame
1635- d = (
1636- list (frame .f_locals )
1637- + list (frame .f_globals )
1638- + list (frame .f_builtins )
1639- )
1640- d = [x for x in d if isinstance (x , str )]
1641-
1642- # Check first if we are in a method and the instance
1643- # has the wrong name as attribute
1644- if 'self' in frame .f_locals :
1645- self = frame .f_locals ['self' ]
1646- try :
1647- has_wrong_name = hasattr (self , wrong_name )
1648- except Exception :
1649- has_wrong_name = False
1650- if has_wrong_name :
1651- return f"self.{ wrong_name } "
16521655
16531656 try :
16541657 import _suggestions
0 commit comments