Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/prompt_toolkit/key_binding/key_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ def remove(self, *args: Keys | str | KeyHandlerCallable) -> None:
self._clear_cache()
else:
# No key binding found for this function. Raise ValueError.
raise ValueError(f"Binding not found: {function!r}")
binding_repr = ", ".join(map(repr, args))
raise ValueError(f"Binding not found: {binding_repr}")

# For backwards-compatibility.
add_binding = add
Expand Down
7 changes: 7 additions & 0 deletions tests/test_key_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_remove_bindings(handlers):
with set_dummy_app():
h = handlers.controlx_controlc
h2 = handlers.controld
h3 = handlers.controla

# Test passing a handler to the remove() function.
bindings = KeyBindings()
Expand All @@ -94,6 +95,12 @@ def test_remove_bindings(handlers):
bindings.remove(Keys.ControlX, Keys.ControlC)
assert len(bindings.bindings) == 1

# Test passing unbound key sequence to the remove() function
with pytest.raises(ValueError):
bindings.remove(h3)
with pytest.raises(ValueError):
bindings.remove(Keys.ControlA)


def test_feed_simple(processor, handlers):
with set_dummy_app():
Expand Down