Skip to content

Commit 51ffb81

Browse files
committed
Keep autocomplete errors from crashing bpython
Perhaps a popup of some sort informing the user that an error has occurred would be better than just swallowing the error as I've done here, but I feel like a misbehaving completer should crash the application. The completer that prompted this for me is FilenameCompletion. I've got a test file in my directory created with `touch $'with\xFFhigh ascii'. If I type an open quote and a w in bpython, it crashes. It's because From python, if I do: >>> import glob >>> glob.glob(u'w*') # this is what FileCompletion will end up calling [u'without high ascii', u'with\uf0ffhigh ascii'] >>> But if I do it from bpython: >>> import glob >>> glob.glob(u'w*'0 [u'without high ascii', 'with\xffhigh ascii'] >>> For some reason, glob is returning one unicode and one str. Then when get_completer calls sorted(matches), sorted throws up when it tries to decode the str from ASCII. I don't know why glob is behaving this way or what the fix is, but I do know that it's not worth crashing bpython whenever I type 'w
1 parent dc0f294 commit 51ffb81

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

bpython/autocomplete.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,14 @@ def get_completer(completers, cursor_offset, line, **kwargs):
544544
double underscore methods like __len__ in method signatures
545545
"""
546546

547-
for completer in completers:
548-
matches = completer.matches(cursor_offset, line, **kwargs)
549-
if matches is not None:
550-
return sorted(matches), (completer if matches else None)
547+
try:
548+
for completer in completers:
549+
matches = completer.matches(cursor_offset, line, **kwargs)
550+
if matches is not None:
551+
return sorted(matches), (completer if matches else None)
552+
except:
553+
pass
554+
551555
return [], None
552556

553557

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy