From 3f0d3ffb2308e72b60ab1938d4d5924b3427c5fa Mon Sep 17 00:00:00 2001 From: Old-Ding <35417409+Old-Ding@users.noreply.github.com> Date: Mon, 13 Jul 2026 09:41:41 +0800 Subject: [PATCH] Allow empty YAML entity lists Treat explicitly empty nested entity lists as valid input instead of indexing the missing first element. This lets generated YAML retain empty include argument lists without raising IndexError. Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com> --- launch_yaml/launch_yaml/entity.py | 2 +- launch_yaml/test/launch_yaml/test_include.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/launch_yaml/launch_yaml/entity.py b/launch_yaml/launch_yaml/entity.py index 93e262688..5d44f77df 100644 --- a/launch_yaml/launch_yaml/entity.py +++ b/launch_yaml/launch_yaml/entity.py @@ -123,7 +123,7 @@ def get_attr( self.__read_keys.add(name) data = self.__element[name] if check_is_list_entity(data_type): - if isinstance(data, list) and isinstance(data[0], dict): + if isinstance(data, list) and (not data or isinstance(data[0], dict)): return [Entity(child, name) for child in data] raise TypeError( "Attribute '{}' of Entity '{}' expected to be a list of dictionaries.".format( diff --git a/launch_yaml/test/launch_yaml/test_include.py b/launch_yaml/test/launch_yaml/test_include.py index 89197fcb4..148b8f260 100644 --- a/launch_yaml/test/launch_yaml/test_include.py +++ b/launch_yaml/test/launch_yaml/test_include.py @@ -61,5 +61,24 @@ def test_include(): assert ls.context.launch_configurations['baz'] == 'BAZ' +def test_include_with_empty_argument_lists(): + """Parse an include action with explicitly empty argument lists.""" + path = (Path(__file__).parent / 'executable.yaml').as_posix() + yaml_file = textwrap.dedent( + """\ + launch: + - include: + file: '{}' + arg: [] + let: [] + """.format(path) + ) + root_entity, parser = load_no_extensions(io.StringIO(yaml_file)) + ld = parser.parse_description(root_entity) + + include = ld.entities[0] + assert include.launch_arguments == () + + if __name__ == '__main__': test_include()