launch icon indicating copy to clipboard operation
launch copied to clipboard

EventHandler should normalize entities into iterable type

Open huweiATgithub opened this issue 10 months ago • 0 comments

The problem

https://github.com/ros2/launch/blob/552bfacde39ebbea9c899450ffdcdfd188c61acd/launch/launch/event_handler.py#L105-L137

In above code, entities: Optional[SomeEntitiesType] = None, entities is marked as SomeEntitiesType. It is not normalized in the __init__ function. In the describe function below, it is used as an iterable actions.extend(self.entities).

Besides, noting that in ExecuteLocal, entities is set to a single LaunchDescriptionEntity many times:

            EventHandler(
                matcher=lambda event: is_a_subclass(event, SignalProcess),
                entities=OpaqueFunction(function=self.__on_signal_process_event),
            )

Proposed fix

I plan to fix this by always making the __entities member an iterable (if not None):

        if isinstance(entities, LaunchDescriptionEntity):
            self.__entities = (entities,)
        else:
            self.__entities = entities

huweiATgithub avatar Feb 24 '25 08:02 huweiATgithub