From e1167fd95f82d6ddd72ee0d9d409afc4b72e621b Mon Sep 17 00:00:00 2001 From: ethernet Date: Wed, 23 Sep 2026 15:46:37 -0400 Subject: [PATCH] fix(yaml): let the pure parser decide what parses on every host libyaml (ruamel's C loader) rejects documents the pure parser accepts, e.g. `hermes config set custom_providers "[{name: ok, base_url: http://h/v1}]"`, so the same command wrote on Windows ARM64 (no clib wheel) and exited 1 on Linux/macOS. safe_load keeps the C fast path and re-reads a C rejection with the pure parser; the accept set now matches across hosts and PyYAML's behaviour on main. --- hermes_yaml.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/hermes_yaml.py b/hermes_yaml.py index 291728aef2..48b9482624 100644 --- a/hermes_yaml.py +++ b/hermes_yaml.py @@ -19,11 +19,23 @@ class _Yaml11Resolver(VersionedResolver): return (1, 1) -def safe_load(stream: str | bytes | IO[str] | IO[bytes]) -> Any: - """Read standard YAML data; existing configs use YAML 1.1 booleans.""" - yaml = YAML(typ="safe") +def _load(document: str | bytes, *, pure: bool) -> Any: + yaml = YAML(typ="safe", pure=pure) yaml.version = (1, 1) - return yaml.load(stream) + return yaml.load(document) + + +def safe_load(stream: str | bytes | IO[str] | IO[bytes]) -> Any: + """Read standard YAML data; existing configs use YAML 1.1 booleans. + + The pure parser defines what parses: Windows ARM64 has no C extension, and libyaml rejects + documents the pure parser accepts (``[{url: http://h}]``), so a C rejection is re-read pure. + """ + document = stream if isinstance(stream, (str, bytes)) else stream.read() + try: + return _load(document, pure=False) + except YAMLError: + return _load(document, pure=True) @overload