Skip to content

Each class owns its declared method keys, settled once at creation - #243

Merged
trissim merged 2 commits into
mainfrom
fix/declared-key-bindings-settled
Nov 6, 2026
Merged

trissim merged 2 commits into
mainfrom
fix/declared-key-bindings-settled

Conversation

@trissim

@trissim trissim commented Nov 6, 2026

Copy link
Copy Markdown

Follow-up to #242. 2 commits, src/textual/dom.py +12/−7.

What changed

1. _declared_key_bindings is settled when a class is created (b-ui, 1432b49)

Before, method_bindings and class_bindings each read base.__dict__.get("_declared_key_bindings", ()), which probes the class body and falls back to a default when the name is missing. MethodBinding.__set_name__ (binding.py:364) runs before __init_subclass__, so DOMNode.__init_subclass__ now sets cls._declared_key_bindings from the class's own body, next to _own_bindings, and both readers use the attribute. DOMNode declares the ClassVar default at dom.py:532. The writer still builds from owner.__dict__, so a subclass can't inherit its parent's keys as its own.

2. One walk finds the DOMNode classes in an MRO (2f21ec9)

Commit 1's method_bindings filtered cls.__mro__ with issubclass(base, DOMNode), and _binding_bases already ran the same filter over the reversed MRO. That is one fact stated at two sites (IMPL-5). _dom_bases() now states it once and both methods use it. object and plain mixins never run DOMNode.__init_subclass__, and none of them declares method keys (b-ui counted 689 owners with Toad loaded, all DOMNode).

Proof

  • Textual: tests/test_binding.py tests/test_binding_inheritance.py tests/test_dynamic_bindings.py gives 26 passed (host, Python 3.14).
  • b-ui ran Textual's selection on commit 1: 347 passed, plus 3 failures (editor_state ×3) that have been red on main since 09c5aec. Toad's acp_log_view, keymap_owner, keymap_screen and keymap_discovery gave 18/18 on an env built from mains.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XbFMSqJMarXn2ZE8iAL7Sd

claude and others added 2 commits November 6, 2026 00:08
method_bindings and class_bindings each read base.__dict__.get("_declared_key_bindings", ()), a class-body probe with a default for when the name is absent. MethodBinding.__set_name__ runs before __init_subclass__, so DOMNode.__init_subclass__ now settles cls._declared_key_bindings beside _own_bindings, and both readers read the attribute. method_bindings walks only DOMNode bases: object and plain mixins never pass __init_subclass__, and none of them declares method keys (689 owners loaded with Toad, all DOMNode).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XbFMSrQKHwQJSkZZaLyQha
method_bindings filtered cls.__mro__ with issubclass(base, DOMNode) and _binding_bases ran the same filter over the reversed MRO: one fact, "which classes of this MRO are DOMNodes", written at two sites. _dom_bases() states it once and both read it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XbFMSqJMarXn2ZE8iAL7Sd
Copilot AI balanced review requested due to automatic review settings November 6, 2026 05:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@trissim
trissim merged commit 72fbf24 into main Nov 6, 2026
3 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants