load_yaml: _load_yaml(): Skip empty included documents

An optional include with a target path that points to a missing
file leaves a trace in the output: _load_yaml() still calls
_merge_at_path() with the empty document, which creates the target
key as an empty mapping.  A root-level optional include of the same
file contributes nothing, so the outcome depends on whether the
spec names a target path.

Skip included documents that are empty: an empty document
contributes nothing, at the root as well as at a target path, and
creates no key.  Update the module docstring accordingly and add
tests covering a missing optional include with a target path.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-08-25 20:08:23 +02:00
commit 90ab62f062
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -988,6 +988,29 @@ class TestIncludeWithPath:
data = load_yaml(pathlib.Path(base) / 'main.yaml')
assert data['section']['opt'] == 'val'
def test_optional_include_missing_target(self, temp_dir: Callable) -> None:
"""A missing optional include at a target path creates no key."""
base = temp_dir(
[
('main.yaml', 'jw.include: -a.b|missing.yaml\nlocal: yes\n'),
]
)
data = load_yaml(pathlib.Path(base) / 'main.yaml')
assert data == {'local': True}
def test_optional_include_missing_existing_target(self, temp_dir: Callable) -> None:
"""A missing optional include leaves an existing target untouched."""
base = temp_dir(
[
(
'main.yaml',
'jw.include: -section|missing.yaml\nsection:\n kept: yes\n',
),
]
)
data = load_yaml(pathlib.Path(base) / 'main.yaml')
assert data == {'section': {'kept': True}}
def test_include_pipe_in_filename(self, temp_dir: Callable) -> None:
"""The first pipe separates target and file, pipes stay in the file."""
base = temp_dir(