mirror of
https://github.com/TeachBooks/manual.git
synced 2026-11-12 22:35:51 +00:00
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.
This commit is contained in:
parent
f4ea60d42c
commit
e12183af9e
1 changed files with 7 additions and 4 deletions
|
|
@ -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):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue