From e12183af9eee6338e765aa6e3bdb7a0e19ac4025 Mon Sep 17 00:00:00 2001 From: Dennis den Ouden-van der Horst Date: Sat, 3 Jan 2026 12:48:34 +0100 Subject: [PATCH] Refactor _should_skip_name for clarity and efficiency Extracted suffix_separator, suffix_start, and suffix_end from cfg at the start of the function to avoid repeated dictionary lookups and improve code readability. --- book/_ext/sphinx_gated_directives/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/book/_ext/sphinx_gated_directives/__init__.py b/book/_ext/sphinx_gated_directives/__init__.py index c650d97..f85538a 100644 --- a/book/_ext/sphinx_gated_directives/__init__.py +++ b/book/_ext/sphinx_gated_directives/__init__.py @@ -210,22 +210,25 @@ def make_end_class(orig_name: str, base_cls: type[Directive]) -> type[Directive] return type(new_cls_name, (base_cls,), attrs) def _should_skip_name(orig_name: str, cfg: dict) -> bool: + suffix_separator = cfg["suffix_separator"] + suffix_start = cfg["suffix_start"] + suffix_end = cfg["suffix_end"] if isinstance(cfg["override_existing"],bool): if cfg["override_existing"] is True: return False else: - if orig_name.endswith(f"{cfg["suffix_separator"]}{cfg["suffix_start"]}"): + if orig_name.endswith(f"{suffix_separator}{suffix_start}"): return True else: - return orig_name.endswith(f"{cfg["suffix_separator"]}{cfg["suffix_end"]}") + return orig_name.endswith(f"{suffix_separator}{suffix_end}") elif isinstance(cfg["override_existing"],list): if orig_name in cfg["override_existing"]: return False else: - if orig_name.endswith(f"{cfg["suffix_separator"]}{cfg["suffix_start"]}"): + if orig_name.endswith(f"{suffix_separator}{suffix_start}"): return True else: - return orig_name.endswith(f"{cfg["suffix_separator"]}{cfg["suffix_end"]}") + return orig_name.endswith(f"{suffix_separator}{suffix_end}") def _register_new_directives(app, env, docnames):