ros2 / launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Apache License 2.0
117 stars 138 forks source link

Unexpected YAML parsing with get_attr and List[Entity] type #762

Open baconbrot opened 4 months ago

baconbrot commented 4 months ago

Bug report

The get_attr method from the YAML entity looks wrong to me when using data_type=List[Entity].

The names of the entities returned by following section

        if check_is_list_entity(data_type):
            if isinstance(data, list) and 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(
                    name, self.type_name
                )
            )

are all set to the name of the parent attribute.

Example

Changing the timer event parse method to accept an actions attribute of data_type=List[Entity] then the above code using following launch.yaml

launch:
  - timer:
      period: 3.0
      actions:
        - log:
            message: 'Timer msg 1!'
        - log:
            message: 'Timer msg 2!'

creates for each log entity an entity with type_name=actions instead of type_name=log.

The children property inside this entity class implements the correct (expected) logic.

Is this logic intended or a bug?

baconbrot commented 3 months ago

Actually I am wrong! This is not a bug but intended behavior. An example use case is the parsing of node params.