From c537182f183a02fb7a85e37c2e9b828465a08fc9 Mon Sep 17 00:00:00 2001 From: Adam Dangoor Date: Tue, 21 Jan 2025 12:49:00 +0000 Subject: [PATCH] Enable using MockInliner in place of `Inliner` for runtime type checking Fixes https://github.com/executablebooks/MyST-Parser/issues/1017. --- myst_parser/mocking.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/myst_parser/mocking.py b/myst_parser/mocking.py index 61a2b172..ac6b62c8 100644 --- a/myst_parser/mocking.py +++ b/myst_parser/mocking.py @@ -34,6 +34,16 @@ class MockInliner: This is parsed to role functions. """ + # Override the ``__class__`` attribute to enable runtime type checking. + # See https://beartype.readthedocs.io/en/latest/faq/#mock-types. + @property + def __class__(self) -> type: + return Inliner + + @__class__.setter + def __class__(self, value: type) -> None: + raise NotImplementedError + def __init__(self, renderer: DocutilsRenderer): """Initialize the mock inliner.""" self._renderer = renderer