You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Has any thought been given to developing an idiomatic Python API for Fast DDS? The API requires a coding style that is fairly unnatural in Python.
Some examples:
Accessing instance variables on objects:
# not idiomaticdata.message()
self.topic_data_type.getName()
# idiomaticdata.messageself.topic_data_type.name
Setting instance variables on objects:
# not idiomaticdata.message("Hello World")
self.topic_data_type.setName("HelloWorld") # p.s., why does this one use "set" and other doesn't?# idiomaticdata.message="Hello World"self.topic_data_type.name="HelloWorld"
Passing objects by reference to have them initialized:
# not idiomaticinfo=fastdds.SampleInfo()
data=HelloWorld.HelloWorld()
reader.take_next_sample(data, info)
# idiomaticdata, info=reader.take_next_sample()
# not idiomaticself.subscriber_qos=fastdds.SubscriberQos()
self.participant.get_default_subscriber_qos(self.subscriber_qos)
# idiomatic, kind of?self.subscriber_qos=self.participant.create_subscriber_qos()
self.subscriber_qos=fastdds.SubscriberQos.create_from(self.participant)
Manual management of resources:
# not idiomaticfactory=fastdds.DomainParticipantFactory.get_instance()
self.participant.delete_contained_entities()
factory.delete_participant(self.participant)
# idiomatic, often happens implicitlydelself.participant
Presumably this is mostly a consequence of using SWIG to generate the Python bindings.
SWIG does have %attribute for wrapping setters and getters in an idiomatic way.
I've also heard decent things about pybind11. This example shows how to handle mapping Python object properties to C++ setters and getters like getName() and setName()
Activity
rgov commentedon Aug 4, 2023
Presumably this is mostly a consequence of using SWIG to generate the Python bindings.
SWIG does have
%attributefor wrapping setters and getters in an idiomatic way.I've also heard decent things about pybind11. This example shows how to handle mapping Python object properties to C++ setters and getters like
getName()andsetName()JLBuenoLopez commentedon Sep 12, 2023
Thanks @rgov for your contribution
I have labeled this as an enhancement and I am moving the ticket to the Ideas discussion forum. For the moment the Python API will remain as it is.