From fb886db971ea68091e1e4f24fc403f2be3b70159 Mon Sep 17 00:00:00 2001 From: Tristan Simas Date: Mon, 16 Nov 2026 12:48:28 -0500 Subject: [PATCH] AbstractHooksMeta comes from metaclass_registry; Textual's copy is deleted Toad's shared contracts use the same metaclass, and importing it from Textual made each of them import Textual, so the Qt client on Android could not share them. The class moved unchanged to metaclass_registry (OpenHCSDev/metaclass-registry#13); _MessagePumpMeta subclasses it from there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XbFMSofn8pw1EZ8PbTeYxm --- pyproject.toml | 1 + src/textual/abstract_hooks.py | 27 --------------------------- src/textual/message_pump.py | 2 +- 3 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 src/textual/abstract_hooks.py diff --git a/pyproject.toml b/pyproject.toml index 22a015ad9d..b94d0e5da8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ rich = ">=14.2.0" #rich = {path="../rich", develop=true} typing-extensions = "^4.4.0" platformdirs = ">=3.6.0,<5" +metaclass-registry = { git = "https://github.com/OpenHCSDev/metaclass-registry", branch = "main" } # start of [syntax] extras # Require tree-sitter >= 0.25.0 and python >= 3.10 diff --git a/src/textual/abstract_hooks.py b/src/textual/abstract_hooks.py deleted file mode 100644 index 95d53559e8..0000000000 --- a/src/textual/abstract_hooks.py +++ /dev/null @@ -1,27 +0,0 @@ -"""Abstract methods enforced without ABCMeta.""" - -from __future__ import annotations - -from typing import Any - - -class AbstractHooksMeta(type): - """A class whose MRO declares an abstract method it still resolves can't be built. - - ABCMeta does the same but replaces isinstance and issubclass, which doubles their - cost on every check. This reads the whole MRO once, at class creation, so a plain - mixin's abstract hooks count as well as a declared base's. Assigning - __abstractmethods__ sets the flag object.__new__ refuses on. - """ - - def __init__( - cls, name: str, bases: tuple[type, ...], namespace: dict[str, Any], **kwargs: Any - ) -> None: - super().__init__(name, bases, namespace, **kwargs) - cls.__abstractmethods__ = frozenset( - member - for base in cls.__mro__ - for member, value in vars(base).items() - if getattr(value, "__isabstractmethod__", False) - and getattr(getattr(cls, member, None), "__isabstractmethod__", False) - ) diff --git a/src/textual/message_pump.py b/src/textual/message_pump.py index 39265b2df4..92a06171e3 100644 --- a/src/textual/message_pump.py +++ b/src/textual/message_pump.py @@ -32,7 +32,7 @@ from weakref import WeakSet, ref from textual import Logger, events, log, messages -from textual.abstract_hooks import AbstractHooksMeta +from metaclass_registry import AbstractHooksMeta from textual._callback import invoke from textual._compat import cached_property from textual._context import NoActiveAppError, active_app, active_message_pump