Skip to content

Commit e75d99d

Browse files
fix cli keymap to return tuple as default and remove shim
--HG-- branch : scroll-frontend extra : rebase_source : 285ed6b1cfaa61fda5ab341d668a1b2c29719ace
1 parent f409901 commit e75d99d

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

bpython/keys.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626

2727
class KeyMap:
2828

29-
def __init__(self):
29+
def __init__(self, default=''):
3030
self.map = {}
31+
self.default = default
3132

3233
def __getitem__(self, key):
3334
if not key:
3435
# Unbound key
35-
return str()
36+
return self.default
3637
elif key in self.map:
3738
return self.map[key]
3839
else:
@@ -45,8 +46,8 @@ def __delitem__(self, key):
4546
def __setitem__(self, key, value):
4647
self.map[key] = value
4748

48-
cli_key_dispatch = KeyMap()
49-
urwid_key_dispatch = KeyMap()
49+
cli_key_dispatch = KeyMap(tuple())
50+
urwid_key_dispatch = KeyMap('')
5051

5152
# fill dispatch with letters
5253
for c in string.ascii_lowercase:

bpython/scrollfrontend/repl.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,6 @@ def add_normal_character(self, char):
307307
def process_event(self, e):
308308
"""Returns True if shutting down, otherwise mutates state of Repl object"""
309309

310-
# shim for weird key_dispatch #TODO patch bpython
311-
def tint(x):
312-
"""Tuple if not tuple - returns one-item tuple if x isn't a tuple"""
313-
return x if isinstance(x, tuple) else tuple(x)
314-
315310
#logging.debug("processing event %r", e)
316311
if isinstance(e, events.WindowChangeEvent):
317312
logging.debug('window change to %d %d', e.width, e.height)
@@ -356,7 +351,7 @@ def tint(x):
356351
raise SystemExit()
357352
elif e == "":
358353
raise KeyboardInterrupt()
359-
elif e in ("",) + tint(key_dispatch[self.config.exit_key]):
354+
elif e in ("",) + key_dispatch[self.config.exit_key]:
360355
raise SystemExit()
361356
elif e in ("\n", "\r", "PAD_ENTER"):
362357
self.on_enter()

0 commit comments

Comments
 (0)