From 6d480056e57cb80ea8ea0461a3ddc817e7ef4039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Tue, 13 Dec 2022 16:15:28 +0000 Subject: [PATCH 1/3] Add a test for binding merging. --- tests/test_dom.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_dom.py b/tests/test_dom.py index e925c5c14..6037abdd0 100644 --- a/tests/test_dom.py +++ b/tests/test_dom.py @@ -45,6 +45,39 @@ def test_validate(): node.toggle_class("1") +def test_inherited_bindings(): + """Test if binding merging is done correctly when (not) inheriting bindings.""" + class A(DOMNode): + BINDINGS = [("a", "a", "a")] + + class B(A): + BINDINGS = [("b", "b", "b")] + + class C(B, inherit_bindings=False): + BINDINGS = [("c", "c", "c")] + + class D(C, inherit_bindings=False): + pass + + class E(D): + BINDINGS = [("e", "e", "e")] + + a = A() + assert list(a._bindings.keys.keys()) == ["a"] + + b = B() + assert list(b._bindings.keys.keys()) == ["a", "b"] + + c = C() + assert list(c._bindings.keys.keys()) == ["c"] + + d = D() + assert not list(d._bindings.keys.keys()) + + e = E() + assert list(e._bindings.keys.keys()) == ["e"] + + @pytest.fixture def search(): """ From 94c05aa876296eb4e666d6ef1f96ee40dda2c012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Tue, 13 Dec 2022 16:16:04 +0000 Subject: [PATCH 2/3] Fix binding merging a la #1336 --- src/textual/dom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/dom.py b/src/textual/dom.py index f1232e54d..bc1d52ee5 100644 --- a/src/textual/dom.py +++ b/src/textual/dom.py @@ -229,7 +229,7 @@ class DOMNode(MessagePump): if issubclass(base, DOMNode): if not base._inherit_bindings: bindings.clear() - bindings.append(Bindings(base.BINDINGS)) + bindings.append(Bindings(base.__dict__.get("BINDINGS", []))) keys = {} for bindings_ in bindings: keys.update(bindings_.keys) From e9a5995c47ee81c501078321a5f656c38ce192cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gir=C3=A3o=20Serr=C3=A3o?= <5621605+rodrigogiraoserrao@users.noreply.github.com> Date: Tue, 13 Dec 2022 16:19:47 +0000 Subject: [PATCH 3/3] Update changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1641b1a3..42111addd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed issue with auto width/height and relative children https://github.com/Textualize/textual/issues/1319 - Fixed issue with offset applied to containers https://github.com/Textualize/textual/issues/1256 - Fixed default CSS retrieval for widgets with no `DEFAULT_CSS` that inherited from widgets with `DEFAULT_CSS` https://github.com/Textualize/textual/issues/1335 +- Fixed merging of `BINDINGS` when binding inheritance is set to `None` https://github.com/Textualize/textual/issues/1351 ## [0.5.0] - 2022-11-20