Skip to content

Commit a8c3018

Browse files
authored
Merge pull request #1352 from Textualize/fix-1351
Fix binding merging when binding inheritance is set to `False`.
2 parents 9acdd70 + e9a5995 commit a8c3018

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2828
- Fixed issue with auto width/height and relative children https://github.com/Textualize/textual/issues/1319
2929
- Fixed issue with offset applied to containers https://github.com/Textualize/textual/issues/1256
3030
- Fixed default CSS retrieval for widgets with no `DEFAULT_CSS` that inherited from widgets with `DEFAULT_CSS` https://github.com/Textualize/textual/issues/1335
31+
- Fixed merging of `BINDINGS` when binding inheritance is set to `None` https://github.com/Textualize/textual/issues/1351
3132

3233
## [0.5.0] - 2022-11-20
3334

src/textual/dom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _merge_bindings(cls) -> Bindings:
229229
if issubclass(base, DOMNode):
230230
if not base._inherit_bindings:
231231
bindings.clear()
232-
bindings.append(Bindings(base.BINDINGS))
232+
bindings.append(Bindings(base.__dict__.get("BINDINGS", [])))
233233
keys = {}
234234
for bindings_ in bindings:
235235
keys.update(bindings_.keys)

tests/test_dom.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,39 @@ def test_validate():
4545
node.toggle_class("1")
4646

4747

48+
def test_inherited_bindings():
49+
"""Test if binding merging is done correctly when (not) inheriting bindings."""
50+
class A(DOMNode):
51+
BINDINGS = [("a", "a", "a")]
52+
53+
class B(A):
54+
BINDINGS = [("b", "b", "b")]
55+
56+
class C(B, inherit_bindings=False):
57+
BINDINGS = [("c", "c", "c")]
58+
59+
class D(C, inherit_bindings=False):
60+
pass
61+
62+
class E(D):
63+
BINDINGS = [("e", "e", "e")]
64+
65+
a = A()
66+
assert list(a._bindings.keys.keys()) == ["a"]
67+
68+
b = B()
69+
assert list(b._bindings.keys.keys()) == ["a", "b"]
70+
71+
c = C()
72+
assert list(c._bindings.keys.keys()) == ["c"]
73+
74+
d = D()
75+
assert not list(d._bindings.keys.keys())
76+
77+
e = E()
78+
assert list(e._bindings.keys.keys()) == ["e"]
79+
80+
4881
def test_get_default_css():
4982
class A(DOMNode):
5083
pass

0 commit comments

Comments
 (0)