From a11e3509573d560937b85a671ff978ac6ea26c86 Mon Sep 17 00:00:00 2001 From: ZZZank <47418975+ZZZank@users.noreply.github.com> Date: Fri, 8 May 2026 13:08:29 +0000 Subject: [PATCH 1/2] add `types.pyi` for improved typing support for classes in `types` --- cyclonedds/idl/types.pyi | 104 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 cyclonedds/idl/types.pyi diff --git a/cyclonedds/idl/types.pyi b/cyclonedds/idl/types.pyi new file mode 100644 index 0000000..91ba4f3 --- /dev/null +++ b/cyclonedds/idl/types.pyi @@ -0,0 +1,104 @@ +from typing import Type, TypeVar, Sequence, Optional, Any, overload + +_T = TypeVar("_T") + +class array: + @overload + @classmethod + def __class_getitem__(cls, item: Type[_T]) -> type[Sequence[_T]]: ... + @overload + @classmethod + def __class_getitem__(cls, item: tuple[Type[_T], int]) -> type[Sequence[_T]]: ... + + def __init__(self, subtype: type, length: int) -> None: ... + def __repr__(self) -> str: ... + def __eq__(self, o: object) -> bool: ... + def __hash__(self) -> int: ... + + +class sequence: + @overload + @classmethod + def __class_getitem__(cls, item: Type[_T]) -> type[Sequence[_T]]: ... + @overload + @classmethod + def __class_getitem__(cls, item: tuple[Type[_T], int]) -> type[Sequence[_T]]: ... + + def __init__(self, subtype: type, max_length: Optional[int] = None) -> None: ... + def __repr__(self) -> str: ... + def __eq__(self, o: object) -> bool: ... + def __hash__(self) -> int: ... + + +class typedef: + @overload + @classmethod + def __class_getitem__(cls, item: tuple[str, Type[_T]]) -> type[_T]: ... + @overload + @classmethod + def __class_getitem__(cls, item: Type[_T]) -> type[_T]: ... + + def __init__(self, name: str, subtype: type) -> None: ... + def __repr__(self) -> str: ... + def __eq__(self, o: object) -> bool: ... + def __hash__(self) -> int: ... + def __call__(self, *args: Any, **kwds: Any) -> Any: ... + @property + def __idl_typename__(self) -> str: ... + + +class bounded_str: + @overload + @classmethod + def __class_getitem__(cls, item: int) -> type[str]: ... + + def __init__(self, max_length: int) -> None: ... + def __repr__(self) -> str: ... + def __eq__(self, o: object) -> bool: ... + def __hash__(self) -> int: ... + + +class ValidUnionHolder: + pass + + +class case(ValidUnionHolder): + @overload + @classmethod + def __class_getitem__(cls, item: tuple[int, Type[_T]]) -> type[Optional[_T]]: ... + @overload + @classmethod + def __class_getitem__(cls, item: Type[_T]) -> type[Optional[_T]]: ... + + def __init__(self, discriminator_value: int | list[int], subtype: type) -> None: ... + def __repr__(self) -> str: ... + def __eq__(self, o: object) -> bool: ... + def __hash__(self) -> int: ... + + +class default(ValidUnionHolder): + @overload + @classmethod + def __class_getitem__(cls, item: Type[_T]) -> type[Optional[_T]]: ... + + def __init__(self, subtype: type) -> None: ... + def __repr__(self) -> str: ... + def __eq__(self, o: object) -> bool: ... + def __hash__(self) -> int: ... + + +# IDL primitive type aliases +char = str +wchar = int +int8 = int +int16 = int +int32 = int +int64 = int +uint8 = int +uint16 = int +uint32 = int +uint64 = int +float32 = float +float64 = float + +NoneType = type \ No newline at end of file From 2afb8f6019eafe995a7b6a7c488b62741a3d0616 Mon Sep 17 00:00:00 2001 From: ZZZank <47418975+ZZZank@users.noreply.github.com> Date: Fri, 8 May 2026 13:08:58 +0000 Subject: [PATCH 2/2] fix primitive types --- cyclonedds/idl/types.pyi | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/cyclonedds/idl/types.pyi b/cyclonedds/idl/types.pyi index 91ba4f3..ada87e6 100644 --- a/cyclonedds/idl/types.pyi +++ b/cyclonedds/idl/types.pyi @@ -89,16 +89,40 @@ class default(ValidUnionHolder): # IDL primitive type aliases char = str +"""The C ``char`` datatype. In Python this is implemented as a single-character string.""" + wchar = int +"""The C ``wchar`` datatype. Do not use, here for completeness.""" + int8 = int +"""A signed 8 bit integer.""" + int16 = int +"""A signed 16 bit integer.""" + int32 = int +"""A signed 32 bit integer.""" + int64 = int +"""A signed 64 bit integer.""" + uint8 = int +"""An unsigned 8 bit integer.""" + uint16 = int +"""An unsigned 16 bit integer.""" + uint32 = int +"""An unsigned 32 bit integer.""" + uint64 = int +"""An unsigned 64 bit integer.""" + float32 = float +"""A 32bit floating point number. In typical C this is a regular ``float``.""" + float64 = float +"""A 64bit floating point number. In typical C this is a regular ``float``.""" -NoneType = type \ No newline at end of file +NoneType = type(None) +"""The NoneType, or a "void" type. This is not included in the OMG IDL spec or in the C library but it can be very useful."""