Repository navigation
Each class owns its declared method keys, settled once at creation - #243
Merged
Merged
Conversation
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
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #242. 2 commits,
src/textual/dom.py+12/−7.What changed
1.
_declared_key_bindingsis settled when a class is created (b-ui, 1432b49)Before,
method_bindingsandclass_bindingseach readbase.__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__, soDOMNode.__init_subclass__now setscls._declared_key_bindingsfrom 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 fromowner.__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_bindingsfilteredcls.__mro__withissubclass(base, DOMNode), and_binding_basesalready 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.objectand plain mixins never runDOMNode.__init_subclass__, and none of them declares method keys (b-ui counted 689 owners with Toad loaded, all DOMNode).Proof
tests/test_binding.py tests/test_binding_inheritance.py tests/test_dynamic_bindings.pygives 26 passed (host, Python 3.14).🤖 Generated with Claude Code
https://claude.ai/code/session_01XbFMSqJMarXn2ZE8iAL7Sd