Skip to content

Commit

Permalink
Make cyclonedds typeof work on derived types (#243)
Browse files Browse the repository at this point in the history
* Make `cyclonedds typeof` work on derived types

This solves

   File "/usr/lib64/python3.11/site-packages/cyclonedds/idl/init.py", line 39, \
   in make_idl_struct \
     bases = tuple(list(*bases) + [IdlStruct])
                   ^^^^^^^^^^^^
   TypeError: 'IdlMeta' object is not iterable

when `cyclonedds typeof` is used to print a derived type.

Signed-off-by: Erik Boasson <[email protected]>
  • Loading branch information
eboasson authored Apr 10, 2024
1 parent 0b45cb8 commit 84220f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cyclonedds/idl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def deserialize_key(cls: Type[_TIS], data: bytes, has_header: bool = True, use_v
def make_idl_struct(class_name: str, typename: str, fields: Dict[str, Any], *, dataclassify=True,
field_annotations: Optional[Dict[str, Dict[str, Any]]] = None,
bases: Tuple[Type[IdlStruct], ...] = ()) -> Type[IdlStruct]:
bases = tuple(list(*bases) + [IdlStruct])
bases = tuple(list(bases) + [IdlStruct])
namespace = IdlMeta.__prepare__(class_name, bases, typename=typename)

for fieldname, _type in fields.items():
Expand Down
17 changes: 15 additions & 2 deletions cyclonedds/tools/cli/idl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from inspect import isclass
from inspect import isclass, getmro
from textwrap import indent
from typing import Any, Type, List

Expand Down Expand Up @@ -161,9 +161,22 @@ def _proc_type(cls, state, _type, top_level=False):
out = cls._annot(_type)

scope, enname = cls._scoped_name(_type.__idl__.idl_transformed_typename)
out += f"struct {enname} {{"
out += f"struct {enname} "
basefields = []
for base in getmro(_type)[1:]:
if not issubclass(base, IdlStruct) or base is IdlStruct:
continue

cls._proc_type(state, base)
basefields.extend(get_extended_type_hints(base).keys())
_, basename = cls._scoped_name(base.__idl__.idl_transformed_typename)
out += f": {basename} "
break
out += "{"
field_annot = get_idl_field_annotations(_type)
for name, _type in get_extended_type_hints(_type).items():
if name in basefields:
continue
out += "\n "
if "key" in field_annot.get(name, {}):
out += "@key "
Expand Down

0 comments on commit 84220f4

Please sign in to comment.