From f28cfec06e3370383c25a96e9b98dd41c947f9e0 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Wed, 19 Oct 2022 16:41:29 +0100 Subject: [PATCH] Fix bindings as tuples --- src/textual/binding.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/textual/binding.py b/src/textual/binding.py index 4b6ea76ad7..3ea0325897 100644 --- a/src/textual/binding.py +++ b/src/textual/binding.py @@ -45,27 +45,28 @@ class Bindings: def __init__(self, bindings: Iterable[BindingType] | None = None) -> None: def make_bindings(bindings: Iterable[BindingType]) -> Iterable[Binding]: for binding in bindings: - if isinstance(binding, Binding): - binding_keys = binding.key.split(",") - if len(binding_keys) > 1: - for key in binding_keys: - new_binding = Binding( - key=key, - action=binding.action, - description=binding.description, - show=binding.show, - key_display=binding.key_display, - universal=binding.universal, - ) - yield new_binding - else: - yield binding - else: + # If it's a tuple of length 3, convert into a Binding first + if isinstance(binding, tuple): if len(binding) != 3: raise BindingError( f"BINDINGS must contain a tuple of three strings, not {binding!r}" ) - yield Binding(*binding) + binding = Binding(*binding) + + binding_keys = binding.key.split(",") + if len(binding_keys) > 1: + for key in binding_keys: + new_binding = Binding( + key=key, + action=binding.action, + description=binding.description, + show=binding.show, + key_display=binding.key_display, + universal=binding.universal, + ) + yield new_binding + else: + yield binding self.keys: MutableMapping[str, Binding] = ( {binding.key: binding for binding in make_bindings(bindings)}