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.
This commit is contained in:
ethernet
2026-09-23 15:46:37 -04:00
parent fe894cca9d
commit e1167fd95f

View File

@@ -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