diff --git a/copier/template.py b/copier/template.py index f903dc186..7c68293f4 100644 --- a/copier/template.py +++ b/copier/template.py @@ -88,7 +88,7 @@ class _Loader(yaml.FullLoader): with conf_path.open("rb") as f: try: - flattened_result = lflatten(yaml.load_all(f, Loader=_Loader)) + flattened_result = lflatten(filter(None, yaml.load_all(f, Loader=_Loader))) except yaml.parser.ParserError as e: raise InvalidConfigFileError(conf_path, quiet) from e diff --git a/tests/test_config.py b/tests/test_config.py index 1d282b91f..8d89a5f10 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -191,6 +191,32 @@ def test_valid_multi_section(tmp_path: Path) -> None: } +def test_empty_section(tmp_path: Path) -> None: + """Empty sections are ignored.""" + build_file_tree( + { + (tmp_path / "copier.yml"): ( + """\ + --- + --- + + --- + your_age: + type: int + your_name: + type: str + --- + """ + ), + } + ) + template = Template(str(tmp_path)) + assert template.questions_data == { + "your_age": {"type": "int"}, + "your_name": {"type": "str"}, + } + + def test_config_data_empty() -> None: template = Template("tests/demo_config_empty") assert template.config_data == {}