From eb76481e33e65e7315360687a4f0d79a5cb9734a Mon Sep 17 00:00:00 2001 From: Tristan Simas Date: Mon, 16 Nov 2026 15:42:58 -0500 Subject: [PATCH] Toad's action families, scopes and binding styles read through OwnDeclarations DeclaredWidgetActions and ActionPresentation drop their hand-written MRO loops. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016gZLdupVQyBzHTmHBC9Cyn --- src/toad/widget_actions.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/toad/widget_actions.py b/src/toad/widget_actions.py index ca00d0c16..ead8b40c8 100644 --- a/src/toad/widget_actions.py +++ b/src/toad/widget_actions.py @@ -89,8 +89,7 @@ class DeclaredWidgetActions(ToadNode): def declared_actions(cls) -> tuple[type[DeclaredAction], ...]: """Capabilities and the widget's own family compose through its MRO.""" return tuple(dict.fromkeys( - member for base in cls.__mro__ - for family in base.__dict__.get("own_actions", ()) + member for family in cls.declared_items("own_actions") for member in family.members_with(family) )) @@ -468,10 +467,11 @@ def __init_subclass__( @classmethod def present_binding(cls, declaration: type[KeyDeclaration], binding: Binding) -> Binding: - scopes = {family: members for base in reversed(cls.__mro__) - for family, members in base.__dict__.get("scopes", {}).items()} - for base in reversed(cls.__mro__): - for style in base.__dict__.get("binding_styles", ()): + scopes = {family: members + for _, declared in cls.own_declarations("scopes", reversed(cls.__mro__)) + for family, members in declared.items()} + for base, styles in cls.own_declarations("binding_styles", reversed(cls.__mro__)): + for style in styles: selected = any(root in declaration.__mro__ for root in scopes.get(base, (KeyDeclaration,))) binding = replace(binding, **{ style.field.name: style.combine(bool(style.field.current(binding)), selected)