Skip to content

Commit

Permalink
Merge pull request Textualize#1352 from Textualize/fix-1351
Browse files Browse the repository at this point in the history
Fix binding merging when binding inheritance is set to `False`.
  • Loading branch information
willmcgugan authored Dec 13, 2022
2 parents 9acdd70 + e9a5995 commit a8c3018
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _merge_bindings(cls) -> Bindings:
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)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]


def test_get_default_css():
class A(DOMNode):
pass
Expand Down

0 comments on commit a8c3018

Please sign in to comment.