From 7fc25e8ab372a23959841cd037da6bf8db920509 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 16 Aug 2026 12:14:03 +0200 Subject: [PATCH] load_yaml: Move module constants above functions The compiled regular expressions _LINK_NAME_RE and _INCLUDE_PATH_RE are defined inline between the functions that use them, which scatters module-level state through the file. Move both of them to the top of the module, next to the IncludeSpec and Includes type aliases, and group them under a Constants section header so that all module-level definitions appear before the first function. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann --- src/python/jw/util/load_yaml.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/python/jw/util/load_yaml.py b/src/python/jw/util/load_yaml.py index 6f9426b..ed808db 100644 --- a/src/python/jw/util/load_yaml.py +++ b/src/python/jw/util/load_yaml.py @@ -8,9 +8,14 @@ from typing import Any, TypeAlias, cast import yaml # type: ignore[import-untyped] +# -- Constants ------------------------------------------------------------------ + IncludeSpec: TypeAlias = tuple[bool, Path, tuple[str, ...]] Includes: TypeAlias = list[IncludeSpec] +_LINK_NAME_RE = re.compile(r'^([a-zA-Z0-9_-]+)\|') +_INCLUDE_PATH_RE = re.compile(r'^([a-zA-Z0-9_.|-]+)\|') + # -- Low-level helpers (call graph leaves) -------------------------------------- def _deep_merge(base: dict[str, Any], override: dict[str, Any]) -> dict[str, Any]: @@ -22,8 +27,6 @@ def _deep_merge(base: dict[str, Any], override: dict[str, Any]) -> dict[str, Any ret[key] = deepcopy(val) return ret -_LINK_NAME_RE = re.compile(r'^([a-zA-Z0-9_-]+)\|') - def _parse_link(value: str) -> tuple[bool, str | None, str]: """Parse a link value into (is_named, name_or_None, path_string). @@ -100,8 +103,6 @@ def _resolve_path( # -- Include helpers ------------------------------------------------------------ -_INCLUDE_PATH_RE = re.compile(r'^([a-zA-Z0-9_.|-]+)\|') - def _parse_include_spec(spec: str, parent: Path) -> IncludeSpec: if not spec: raise ValueError('Empty include spec')