Including other idl files doesnt work
Hello,
I have an issue with including other types in the python generated code. For example creating the two files:
TypeTest.idl
#include "OtherType.idl"
module TypeTest
{
struct Type1
{
long type1_long;
};
struct Type2
{
double type2_d;
Type1 type2_type1;
OtherType::Type3 other_type;
};
};
OtherType.idl:
module OtherType
{
struct Type3
{
double other_type;
};
};
Using the test code:
#!/usr/bin/python3
import fastdds
from TypeTest import TypeTest
from OtherType import OtherType
t1 = TypeTest.Type1
t1.type1_long = 1111;
print('t1', t1)
print('t1 dir', dir(t1), end='\n\n')
t2 = TypeTest.Type2
print('t2', t2)
print('t2 dir', dir(t2))
t2.type2_d = 18.0
t2.type2_type1 = t1
print('t2 d', t2.type2_d)
print('t2 t1', t2.type2_type1.type1_long)
other = OtherType.Type3
print('other', dir(other), end='\n\n')
print('t2 other', dir(t2.other_type), end='\n\n')
# This is okay
other.other_type = 10.0
print('other type', other.other_type)
#Both of these fail
t2.other_type.other_type = 10.0 #set
print('other', t2.other_type.other_type) #get
Output:
❯ ./test_types.py
t1 <class 'TypeTest.TypeTest.Type1'>
t1 dir ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__swig_destroy__', '__weakref__', 'thisown', 'type1_long']
t2 <class 'TypeTest.TypeTest.Type2'>
t2 dir ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__swig_destroy__', '__weakref__', 'other_type', 'thisown', 'type2_d', 'type2_type1']
t2 d 18.0
t2 t1 1111
other ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__swig_destroy__', '__weakref__', 'other_type', 'thisown']
t2 other ['__class__', '__delattr__', '__delete__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__isabstractmethod__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__set__', '__set_name__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'deleter', 'fdel', 'fget', 'fset', 'getter', 'setter']
other type 10.0
Traceback (most recent call last):
File "/home/jtroeth/software/Fast-DDS-python/fastdds_python_examples/TypesBug/./test_types.py", line 27, in <module>
t2.other_type.other_type = 10.0 #set
AttributeError: 'property' object has no attribute 'other_type'
We can see the dir(other) is okay and has a dict method and shows a double variable "other_type". dir (t2.other_type) has no dict and is missing the double variable other_type.
Setting and getting other_type for struct "other" is okay. Setting and Getting the variable other_type via TypeTest t2 is invalid.
Is this the expected behavior?
Thanks
Okay it looks like creating an instance of TypeTest.Type2 does not create and instance of OtherType.Type3 for the other_type variable. Setting the variable to an instance after creation works:
o = OtherType.Type3
t3 = TypeTest.Type2
t3.other_type_var = o #now and instance
t3.other_type_var = OtherType.Type3 #or now and instance
# now this value can be set/get
t3.other_type_var.other_type = 19.0
print(t2.other_type_var.other_type)
Does it make sense that you have to set this manually on initialization?
======================================================================== Further, Why does this happen:
#!/usr/bin/python3
import fastdds
from TypeTest import TypeTest
from OtherType import OtherType
o = OtherType.Type3
t1 = TypeTest.Type2
t2 = TypeTest.Type2
t1.type2_d = 7777.0
print('a variable that is set', t1.type2_d)
print('a variable that is not set', t2.type2_d)
Output:
a variable that is set 7777.0
a variable that is not set 7777.0