Skip to content

Commit 35df151

Browse files
committed
rename get_key to get_bindings_for_key
1 parent 146e65d commit 35df151

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/textual/binding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ def bind(
206206
)
207207
)
208208

209-
def get_key(self, key: str) -> list[Binding]:
210-
"""Get a binding if it exists.
209+
def get_bindings_for_key(self, key: str) -> list[Binding]:
210+
"""Get a list of bindings for a given key.
211211
212212
Args:
213213
key: Key to look up.
@@ -216,7 +216,7 @@ def get_key(self, key: str) -> list[Binding]:
216216
NoBinding: If the binding does not exist.
217217
218218
Returns:
219-
A binding object for the key,
219+
A list of bindings associated with the key.
220220
"""
221221
try:
222222
return self.keys[key]

tests/test_binding.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ def more_bindings():
2727

2828

2929
def test_bindings_get_key(bindings):
30-
assert bindings.get_key("b") == [
30+
assert bindings.get_bindings_for_key("b") == [
3131
Binding("b", action="action1", description="description1")
3232
]
33-
assert bindings.get_key("c") == [BINDING2]
33+
assert bindings.get_bindings_for_key("c") == [BINDING2]
3434
with pytest.raises(NoBinding):
35-
bindings.get_key("control+meta+alt+shift+super+hyper+t")
35+
bindings.get_bindings_for_key("control+meta+alt+shift+super+hyper+t")
3636

3737

3838
def test_bindings_get_key_spaced_list(more_bindings):
39-
assert more_bindings.get_key("d")[0].action == more_bindings.get_key("e")[0].action
39+
assert (
40+
more_bindings.get_bindings_for_key("d")[0].action
41+
== more_bindings.get_bindings_for_key("e")[0].action
42+
)
4043

4144

4245
def test_bindings_merge_simple(bindings):
@@ -69,7 +72,7 @@ def test_bad_binding_tuple():
6972
def test_binding_from_tuples():
7073
assert BindingsMap(
7174
((BINDING2.key, BINDING2.action, BINDING2.description),)
72-
).get_key("c") == [BINDING2]
75+
).get_bindings_for_key("c") == [BINDING2]
7376

7477

7578
def test_shown():

tests/test_binding_inheritance.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def test_just_app_no_bindings() -> None:
4343
"ctrl+c",
4444
"ctrl+backslash",
4545
]
46-
assert pilot.app._bindings.get_key("ctrl+c")[0].priority is True
46+
assert pilot.app._bindings.get_bindings_for_key("ctrl+c")[0].priority is True
4747

4848

4949
##############################################################################
@@ -67,8 +67,8 @@ async def test_just_app_alpha_binding() -> None:
6767
assert sorted(pilot.app._bindings.keys.keys()) == sorted(
6868
["ctrl+c", "ctrl+backslash", "a"]
6969
)
70-
assert pilot.app._bindings.get_key("ctrl+c")[0].priority is True
71-
assert pilot.app._bindings.get_key("a")[0].priority is True
70+
assert pilot.app._bindings.get_bindings_for_key("ctrl+c")[0].priority is True
71+
assert pilot.app._bindings.get_bindings_for_key("a")[0].priority is True
7272

7373

7474
##############################################################################
@@ -91,8 +91,8 @@ async def test_just_app_low_priority_alpha_binding() -> None:
9191
assert sorted(pilot.app._bindings.keys.keys()) == sorted(
9292
["ctrl+c", "ctrl+backslash", "a"]
9393
)
94-
assert pilot.app._bindings.get_key("ctrl+c")[0].priority is True
95-
assert pilot.app._bindings.get_key("a")[0].priority is False
94+
assert pilot.app._bindings.get_bindings_for_key("ctrl+c")[0].priority is True
95+
assert pilot.app._bindings.get_bindings_for_key("a")[0].priority is False
9696

9797

9898
##############################################################################
@@ -121,7 +121,7 @@ def on_mount(self) -> None:
121121
async def test_app_screen_with_bindings() -> None:
122122
"""Test a screen with a single key binding defined."""
123123
async with AppWithScreenThatHasABinding().run_test() as pilot:
124-
assert pilot.app.screen._bindings.get_key("a")[0].priority is True
124+
assert pilot.app.screen._bindings.get_bindings_for_key("a")[0].priority is True
125125

126126

127127
##############################################################################
@@ -150,7 +150,7 @@ def on_mount(self) -> None:
150150
async def test_app_screen_with_low_bindings() -> None:
151151
"""Test a screen with a single low-priority key binding defined."""
152152
async with AppWithScreenThatHasALowBinding().run_test() as pilot:
153-
assert pilot.app.screen._bindings.get_key("a")[0].priority is False
153+
assert pilot.app.screen._bindings.get_bindings_for_key("a")[0].priority is False
154154

155155

156156
##############################################################################

0 commit comments

Comments
 (0)