From 73d7f3bcbdaabf36f7ba561f4478baccd105a430 Mon Sep 17 00:00:00 2001 From: Kazuya Takei Date: Sun, 17 Mar 2024 18:58:56 +0900 Subject: [PATCH] feat: For handler expected to return value --- src/atsphinx/helpers/decorators.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/atsphinx/helpers/decorators.py b/src/atsphinx/helpers/decorators.py index 27808e8..edb125c 100644 --- a/src/atsphinx/helpers/decorators.py +++ b/src/atsphinx/helpers/decorators.py @@ -69,6 +69,7 @@ def emit_only( builders: Optional[List[str]] = None, formats: Optional[List[str]] = None, loglevel: int = logging.INFO, + return_alt: Any = None, ): """Restict event handler workings by builder types or formats. @@ -91,6 +92,7 @@ def setup(app): :params builders: List of builder names for restrict target. :params formats: List of format types for restrict target. + :params return_alt: Return value if guard is worked. """ if builders is None and formats is None: Logger.log( @@ -108,13 +110,13 @@ def __only(app: Sphinx, *args, **kwargs) -> Any: loglevel, f"{func.__name__} is not supported '{app.builder.name}' builder.", ) - return + return return_alt if formats and app.builder.format not in formats: logger.log( loglevel, f"{func.__name__} is not supported '{app.builder.format}' format.", ) - return + return return_alt return func(app, *args, **kwargs) return __only