X Tutup
Skip to content

Commit 75e8e35

Browse files
lohmatajamlauter
authored andcommitted
Fix p_key to catch exceptions from get_source_of_current_name
1 parent f17eeec commit 75e8e35

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

bpython/cli.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,14 +968,16 @@ def p_key(self, key):
968968
return ''
969969

970970
elif key in key_dispatch[config.show_source_key]:
971-
source = self.get_source_of_current_name()
972-
if source is not None:
971+
try:
972+
source = self.get_source_of_current_name()
973973
if config.highlight_show_source:
974974
source = format(PythonLexer().get_tokens(source),
975975
TerminalFormatter())
976976
page(source)
977-
else:
978-
self.statusbar.message(_('Cannot show source.'))
977+
except (ValueError, NameError), e:
978+
self.statusbar.message(_(e))
979+
except (AttributeError, IOError, TypeError), e:
980+
self.statusbar.message(_('Failed to get source: %s' % e))
979981
return ''
980982

981983
elif key in ('\n', '\r', 'PADENTER'):

0 commit comments

Comments
 (0)
X Tutup