Skip to content

Commit

Permalink
Fix empty files included by \!include_dir_named
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Jan 20, 2024
1 parent b2ba808 commit a7ca52a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion homeassistant/util/yaml/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,12 @@ def _include_dir_named_yaml(loader: LoaderType, node: yaml.nodes.Node) -> NodeDi
filename = os.path.splitext(os.path.basename(fname))[0]
if os.path.basename(fname) == SECRET_YAML:
continue
mapping[filename] = load_yaml(fname, loader.secrets)
loaded_yaml = load_yaml(fname, loader.secrets)
if loaded_yaml is None:
# Special case, an empty file included by !include_dir_named is treated
# an an empty dictionary
loaded_yaml = NodeDictClass()
mapping[filename] = loaded_yaml
return _add_reference(mapping, loader, node)


Expand Down
2 changes: 1 addition & 1 deletion tests/util/yaml/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_include_dir_list_recursive(
),
(
{"/test/first.yaml": "1", "/test/second.yaml": None},
{"first": 1, "second": None},
{"first": 1, "second": {}},
),
],
)
Expand Down

0 comments on commit a7ca52a

Please sign in to comment.