From a141272e8cf8e38daadac0613e1a65b2a7c041ae Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Sat, 31 Jan 2026 19:05:47 -0800 Subject: [PATCH 1/6] test Signed-off-by: Michael Carlstrom --- .../msg/_bounded_sequences.py | 1577 +++++++++++++++++ 1 file changed, 1577 insertions(+) create mode 100644 build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_bounded_sequences.py diff --git a/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_bounded_sequences.py b/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_bounded_sequences.py new file mode 100644 index 00000000..5c3aee8b --- /dev/null +++ b/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_bounded_sequences.py @@ -0,0 +1,1577 @@ +# generated from rosidl_generator_py/resource/_idl.py.em +# with input from rosidl_generator_py:msg/BoundedSequences.idl +# generated code does not contain a copyright notice + +from __future__ import annotations + +import collections.abc +from os import getenv +import typing + +import rosidl_pycommon.interface_base_classes + +# This is being done at the module level and not on the instance level to avoid looking +# for the same variable multiple times on each instance. This variable is not supposed to +# change during runtime so it makes sense to only look for it once. +ros_python_check_fields = getenv('ROS_PYTHON_CHECK_FIELDS', default='') + + +if typing.TYPE_CHECKING: + from rosidl_generator_py.msg import Constants + from ctypes import Structure + + class PyCapsule(Structure): + pass # don't need to define the full structure + from rosidl_generator_py.msg import BasicTypes + from rosidl_generator_py.msg import Defaults + + +# Import statements for member types + +# Member 'char_values' +# Member 'float32_values' +# Member 'float64_values' +# Member 'int8_values' +# Member 'uint8_values' +# Member 'int16_values' +# Member 'uint16_values' +# Member 'int32_values' +# Member 'uint32_values' +# Member 'int64_values' +# Member 'uint64_values' +# Member 'char_values_default' +# Member 'float32_values_default' +# Member 'float64_values_default' +# Member 'int8_values_default' +# Member 'uint8_values_default' +# Member 'int16_values_default' +# Member 'uint16_values_default' +# Member 'int32_values_default' +# Member 'uint32_values_default' +# Member 'int64_values_default' +# Member 'uint64_values_default' +import array # noqa: E402, I100 + +import builtins # noqa: E402, I100 + +import math # noqa: E402, I100 + +import rosidl_parser.definition # noqa: E402, I100 + + +class Metaclass_BoundedSequences(rosidl_pycommon.interface_base_classes.MessageTypeSupportMeta): + """Metaclass of message 'BoundedSequences'.""" + + _CREATE_ROS_MESSAGE: typing.ClassVar[typing.Optional[PyCapsule]] = None + _CONVERT_FROM_PY: typing.ClassVar[typing.Optional[PyCapsule]] = None + _CONVERT_TO_PY: typing.ClassVar[typing.Optional[PyCapsule]] = None + _DESTROY_ROS_MESSAGE: typing.ClassVar[typing.Optional[PyCapsule]] = None + _TYPE_SUPPORT: typing.ClassVar[typing.Optional[PyCapsule]] = None + + class BoundedSequencesConstants(typing.TypedDict): + pass + + __constants: BoundedSequencesConstants = { + } + + @classmethod + def __import_type_support__(cls) -> None: + try: + from rosidl_generator_py import import_type_support # type: ignore[attr-defined] + module = import_type_support('rosidl_generator_py') + except ImportError: + import logging + import traceback + logger = logging.getLogger( + 'rosidl_generator_py.msg.BoundedSequences') + logger.debug( + 'Failed to import needed modules for type support:\n' + + traceback.format_exc()) + else: + cls._CREATE_ROS_MESSAGE = module.create_ros_message_msg__msg__bounded_sequences + cls._CONVERT_FROM_PY = module.convert_from_py_msg__msg__bounded_sequences + cls._CONVERT_TO_PY = module.convert_to_py_msg__msg__bounded_sequences + cls._TYPE_SUPPORT = module.type_support_msg__msg__bounded_sequences + cls._DESTROY_ROS_MESSAGE = module.destroy_ros_message_msg__msg__bounded_sequences + + from rosidl_generator_py.msg import BasicTypes + if BasicTypes._TYPE_SUPPORT is None: + BasicTypes.__import_type_support__() + + from rosidl_generator_py.msg import Constants + if Constants._TYPE_SUPPORT is None: + Constants.__import_type_support__() + + from rosidl_generator_py.msg import Defaults + if Defaults._TYPE_SUPPORT is None: + Defaults.__import_type_support__() + + @classmethod + def __prepare__(metacls, name: str, bases: tuple[type[typing.Any], ...], /, **kwds: typing.Any) -> collections.abc.MutableMapping[str, object]: + # list constant names here so that they appear in the help text of + # the message class under "Data and other attributes defined here:" + # as well as populate each message instance + return { + 'BOOL_VALUES_DEFAULT__DEFAULT': [False, True, False], + 'BYTE_VALUES_DEFAULT__DEFAULT': [b'\x00', b'\x01', b'\xff'], + 'CHAR_VALUES_DEFAULT__DEFAULT': array.array('B', (0, 1, 127, )), + 'FLOAT32_VALUES_DEFAULT__DEFAULT': array.array('f', (1.125, 0.0, -1.125, )), + 'FLOAT64_VALUES_DEFAULT__DEFAULT': array.array('d', (3.1415, 0.0, -3.1415, )), + 'INT8_VALUES_DEFAULT__DEFAULT': array.array('b', (0, 127, -128, )), + 'UINT8_VALUES_DEFAULT__DEFAULT': array.array('B', (0, 1, 255, )), + 'INT16_VALUES_DEFAULT__DEFAULT': array.array('h', (0, 32767, -32768, )), + 'UINT16_VALUES_DEFAULT__DEFAULT': array.array('H', (0, 1, 65535, )), + 'INT32_VALUES_DEFAULT__DEFAULT': array.array('i', (0, 2147483647, -2147483648, )), + 'UINT32_VALUES_DEFAULT__DEFAULT': array.array('I', (0, 1, 4294967295, )), + 'INT64_VALUES_DEFAULT__DEFAULT': array.array('q', (0, 9223372036854775807, -9223372036854775808, )), + 'UINT64_VALUES_DEFAULT__DEFAULT': array.array('Q', (0, 1, 18446744073709551615, )), + 'STRING_VALUES_DEFAULT__DEFAULT': ['', 'max value', 'min value'], + } + + @property + def BOOL_VALUES_DEFAULT__DEFAULT(cls) -> list[bool]: + """Return default value for message field 'bool_values_default'.""" + return [False, True, False] + + @property + def BYTE_VALUES_DEFAULT__DEFAULT(cls) -> list[bytes]: + """Return default value for message field 'byte_values_default'.""" + return [b'\x00', b'\x01', b'\xff'] + + @property + def CHAR_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: + """Return default value for message field 'char_values_default'.""" + return array.array('B', (0, 1, 127, )) + + @property + def FLOAT32_VALUES_DEFAULT__DEFAULT(cls) -> array.array[float]: + """Return default value for message field 'float32_values_default'.""" + return array.array('f', (1.125, 0.0, -1.125, )) + + @property + def FLOAT64_VALUES_DEFAULT__DEFAULT(cls) -> array.array[float]: + """Return default value for message field 'float64_values_default'.""" + return array.array('d', (3.1415, 0.0, -3.1415, )) + + @property + def INT8_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: + """Return default value for message field 'int8_values_default'.""" + return array.array('b', (0, 127, -128, )) + + @property + def UINT8_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: + """Return default value for message field 'uint8_values_default'.""" + return array.array('B', (0, 1, 255, )) + + @property + def INT16_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: + """Return default value for message field 'int16_values_default'.""" + return array.array('h', (0, 32767, -32768, )) + + @property + def UINT16_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: + """Return default value for message field 'uint16_values_default'.""" + return array.array('H', (0, 1, 65535, )) + + @property + def INT32_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: + """Return default value for message field 'int32_values_default'.""" + return array.array('i', (0, 2147483647, -2147483648, )) + + @property + def UINT32_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: + """Return default value for message field 'uint32_values_default'.""" + return array.array('I', (0, 1, 4294967295, )) + + @property + def INT64_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: + """Return default value for message field 'int64_values_default'.""" + return array.array('q', (0, 9223372036854775807, -9223372036854775808, )) + + @property + def UINT64_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: + """Return default value for message field 'uint64_values_default'.""" + return array.array('Q', (0, 1, 18446744073709551615, )) + + @property + def STRING_VALUES_DEFAULT__DEFAULT(cls) -> list[str]: + """Return default value for message field 'string_values_default'.""" + return ['', 'max value', 'min value'] + + +class BoundedSequences(rosidl_pycommon.interface_base_classes.BaseMessage, metaclass=Metaclass_BoundedSequences): + """Message class 'BoundedSequences'.""" + + __slots__ = [ + '_bool_values', + '_byte_values', + '_char_values', + '_float32_values', + '_float64_values', + '_int8_values', + '_uint8_values', + '_int16_values', + '_uint16_values', + '_int32_values', + '_uint32_values', + '_int64_values', + '_uint64_values', + '_string_values', + '_basic_types_values', + '_constants_values', + '_defaults_values', + '_bool_values_default', + '_byte_values_default', + '_char_values_default', + '_float32_values_default', + '_float64_values_default', + '_int8_values_default', + '_uint8_values_default', + '_int16_values_default', + '_uint16_values_default', + '_int32_values_default', + '_uint32_values_default', + '_int64_values_default', + '_uint64_values_default', + '_string_values_default', + '_alignment_check', + '_check_fields', + ] + + _fields_and_field_types: dict[str, str] = { + 'bool_values': 'sequence', + 'byte_values': 'sequence', + 'char_values': 'sequence', + 'float32_values': 'sequence', + 'float64_values': 'sequence', + 'int8_values': 'sequence', + 'uint8_values': 'sequence', + 'int16_values': 'sequence', + 'uint16_values': 'sequence', + 'int32_values': 'sequence', + 'uint32_values': 'sequence', + 'int64_values': 'sequence', + 'uint64_values': 'sequence', + 'string_values': 'sequence', + 'basic_types_values': 'sequence', + 'constants_values': 'sequence', + 'defaults_values': 'sequence', + 'bool_values_default': 'sequence', + 'byte_values_default': 'sequence', + 'char_values_default': 'sequence', + 'float32_values_default': 'sequence', + 'float64_values_default': 'sequence', + 'int8_values_default': 'sequence', + 'uint8_values_default': 'sequence', + 'int16_values_default': 'sequence', + 'uint16_values_default': 'sequence', + 'int32_values_default': 'sequence', + 'uint32_values_default': 'sequence', + 'int64_values_default': 'sequence', + 'uint64_values_default': 'sequence', + 'string_values_default': 'sequence', + 'alignment_check': 'int32', + } + + # This attribute is used to store an rosidl_parser.definition variable + # related to the data type of each of the components the message. + SLOT_TYPES: tuple[rosidl_parser.definition.AbstractType, ...] = ( + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('boolean'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('octet'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint8'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('float'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('double'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int8'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint8'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int16'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint16'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int32'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint32'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int64'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint64'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.UnboundedString(), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.NamespacedType(['rosidl_generator_py', 'msg'], 'BasicTypes'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.NamespacedType(['rosidl_generator_py', 'msg'], 'Constants'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.NamespacedType(['rosidl_generator_py', 'msg'], 'Defaults'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('boolean'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('octet'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint8'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('float'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('double'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int8'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint8'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int16'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint16'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int32'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint32'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int64'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint64'), 3), # noqa: E501 + rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.UnboundedString(), 3), # noqa: E501 + rosidl_parser.definition.BasicType('int32'), # noqa: E501 + ) + + def __init__(self, *, + bool_values: typing.Optional[collections.abc.Sequence[bool]] = None, # noqa: E501 + byte_values: typing.Optional[collections.abc.Sequence[bytes]] = None, # noqa: E501 + char_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + float32_values: typing.Optional[typing.Union[array.array[float], collections.abc.Sequence[float]]] = None, # noqa: E501 + float64_values: typing.Optional[typing.Union[array.array[float], collections.abc.Sequence[float]]] = None, # noqa: E501 + int8_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + uint8_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + int16_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + uint16_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + int32_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + uint32_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + int64_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + uint64_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + string_values: typing.Optional[collections.abc.Sequence[str]] = None, # noqa: E501 + basic_types_values: typing.Optional[collections.abc.Sequence[BasicTypes]] = None, # noqa: E501 + constants_values: typing.Optional[collections.abc.Sequence[Constants]] = None, # noqa: E501 + defaults_values: typing.Optional[collections.abc.Sequence[Defaults]] = None, # noqa: E501 + bool_values_default: typing.Optional[collections.abc.Sequence[bool]] = None, # noqa: E501 + byte_values_default: typing.Optional[collections.abc.Sequence[bytes]] = None, # noqa: E501 + char_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + float32_values_default: typing.Optional[typing.Union[array.array[float], collections.abc.Sequence[float]]] = None, # noqa: E501 + float64_values_default: typing.Optional[typing.Union[array.array[float], collections.abc.Sequence[float]]] = None, # noqa: E501 + int8_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + uint8_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + int16_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + uint16_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + int32_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + uint32_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + int64_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + uint64_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 + string_values_default: typing.Optional[collections.abc.Sequence[str]] = None, # noqa: E501 + alignment_check: typing.Optional[int] = None, # noqa: E501 + check_fields: typing.Optional[bool] = None) -> None: + if check_fields is not None: + self._check_fields = check_fields + else: + self._check_fields = ros_python_check_fields == '1' + self.bool_values = bool_values if bool_values is not None else [] + self.byte_values = byte_values if byte_values is not None else [] + self.char_values = char_values if char_values is not None else array.array('B', []) + self.float32_values = float32_values if float32_values is not None else array.array('f', []) + self.float64_values = float64_values if float64_values is not None else array.array('d', []) + self.int8_values = int8_values if int8_values is not None else array.array('b', []) + self.uint8_values = uint8_values if uint8_values is not None else array.array('B', []) + self.int16_values = int16_values if int16_values is not None else array.array('h', []) + self.uint16_values = uint16_values if uint16_values is not None else array.array('H', []) + self.int32_values = int32_values if int32_values is not None else array.array('i', []) + self.uint32_values = uint32_values if uint32_values is not None else array.array('I', []) + self.int64_values = int64_values if int64_values is not None else array.array('q', []) + self.uint64_values = uint64_values if uint64_values is not None else array.array('Q', []) + self.string_values = string_values if string_values is not None else [] + self.basic_types_values = basic_types_values if basic_types_values is not None else [] + self.constants_values = constants_values if constants_values is not None else [] + self.defaults_values = defaults_values if defaults_values is not None else [] + self.bool_values_default = bool_values_default if bool_values_default is not None else BoundedSequences.BOOL_VALUES_DEFAULT__DEFAULT + self.byte_values_default = byte_values_default if byte_values_default is not None else BoundedSequences.BYTE_VALUES_DEFAULT__DEFAULT + self.char_values_default = char_values_default if char_values_default is not None else BoundedSequences.CHAR_VALUES_DEFAULT__DEFAULT + self.float32_values_default = float32_values_default if float32_values_default is not None else BoundedSequences.FLOAT32_VALUES_DEFAULT__DEFAULT + self.float64_values_default = float64_values_default if float64_values_default is not None else BoundedSequences.FLOAT64_VALUES_DEFAULT__DEFAULT + self.int8_values_default = int8_values_default if int8_values_default is not None else BoundedSequences.INT8_VALUES_DEFAULT__DEFAULT + self.uint8_values_default = uint8_values_default if uint8_values_default is not None else BoundedSequences.UINT8_VALUES_DEFAULT__DEFAULT + self.int16_values_default = int16_values_default if int16_values_default is not None else BoundedSequences.INT16_VALUES_DEFAULT__DEFAULT + self.uint16_values_default = uint16_values_default if uint16_values_default is not None else BoundedSequences.UINT16_VALUES_DEFAULT__DEFAULT + self.int32_values_default = int32_values_default if int32_values_default is not None else BoundedSequences.INT32_VALUES_DEFAULT__DEFAULT + self.uint32_values_default = uint32_values_default if uint32_values_default is not None else BoundedSequences.UINT32_VALUES_DEFAULT__DEFAULT + self.int64_values_default = int64_values_default if int64_values_default is not None else BoundedSequences.INT64_VALUES_DEFAULT__DEFAULT + self.uint64_values_default = uint64_values_default if uint64_values_default is not None else BoundedSequences.UINT64_VALUES_DEFAULT__DEFAULT + self.string_values_default = string_values_default if string_values_default is not None else BoundedSequences.STRING_VALUES_DEFAULT__DEFAULT + self.alignment_check = alignment_check if alignment_check is not None else int() + + def __repr__(self) -> str: + typename = self.__class__.__module__.split('.') + typename.pop() + typename.append(self.__class__.__name__) + args: list[str] = [] + for s, t in zip(self.get_fields_and_field_types().keys(), self.SLOT_TYPES): + field = getattr(self, s) + fieldstr = repr(field) + # We use Python array type for fields that can be directly stored + # in them, and "normal" sequences for everything else. If it is + # a type that we store in an array, strip off the 'array' portion. + if ( + isinstance(t, rosidl_parser.definition.AbstractSequence) and + isinstance(t.value_type, rosidl_parser.definition.BasicType) and + t.value_type.typename in ['float', 'double', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', 'uint64'] + ): + if len(field) == 0: + fieldstr = '[]' + else: + if self._check_fields: + assert fieldstr.startswith('array(') + prefix = "array('X', " + suffix = ')' + fieldstr = fieldstr[len(prefix):-len(suffix)] + args.append(s + '=' + fieldstr) + return '%s(%s)' % ('.'.join(typename), ', '.join(args)) + + def __eq__(self, other: object) -> bool: + if not isinstance(other, BoundedSequences): + return False + if self.bool_values != other.bool_values: + return False + if self.byte_values != other.byte_values: + return False + if self.char_values != other.char_values: + return False + if self.float32_values != other.float32_values: + return False + if self.float64_values != other.float64_values: + return False + if self.int8_values != other.int8_values: + return False + if self.uint8_values != other.uint8_values: + return False + if self.int16_values != other.int16_values: + return False + if self.uint16_values != other.uint16_values: + return False + if self.int32_values != other.int32_values: + return False + if self.uint32_values != other.uint32_values: + return False + if self.int64_values != other.int64_values: + return False + if self.uint64_values != other.uint64_values: + return False + if self.string_values != other.string_values: + return False + if self.basic_types_values != other.basic_types_values: + return False + if self.constants_values != other.constants_values: + return False + if self.defaults_values != other.defaults_values: + return False + if self.bool_values_default != other.bool_values_default: + return False + if self.byte_values_default != other.byte_values_default: + return False + if self.char_values_default != other.char_values_default: + return False + if self.float32_values_default != other.float32_values_default: + return False + if self.float64_values_default != other.float64_values_default: + return False + if self.int8_values_default != other.int8_values_default: + return False + if self.uint8_values_default != other.uint8_values_default: + return False + if self.int16_values_default != other.int16_values_default: + return False + if self.uint16_values_default != other.uint16_values_default: + return False + if self.int32_values_default != other.int32_values_default: + return False + if self.uint32_values_default != other.uint32_values_default: + return False + if self.int64_values_default != other.int64_values_default: + return False + if self.uint64_values_default != other.uint64_values_default: + return False + if self.string_values_default != other.string_values_default: + return False + if self.alignment_check != other.alignment_check: + return False + return True + + @classmethod + def get_fields_and_field_types(cls) -> dict[str, str]: + from copy import copy + return copy(cls._fields_and_field_types) + + @builtins.property + def bool_values(self) -> collections.abc.Sequence[bool]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'bool_values'.""" + return self._bool_values + + @bool_values.setter + def bool_values(self, value: collections.abc.Sequence[bool]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, bool) for v in value) and + True), \ + "The 'bool_values' field must be sequence with length <= 3 and each value of type bool" + self._bool_values = value + + @builtins.property + def byte_values(self) -> collections.abc.Sequence[bytes]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'byte_values'.""" + return self._byte_values + + @byte_values.setter + def byte_values(self, value: collections.abc.Sequence[bytes]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, bytes) for v in value) and + True), \ + "The 'byte_values' field must be sequence with length <= 3 and each value of type bytes" + self._byte_values = value + + @builtins.property + def char_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'char_values'.""" + return self._char_values + + @char_values.setter + def char_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'B', \ + "The 'char_values' array.array() must have the type code of 'B'" + assert len(value) <= 3, \ + "The 'char_values' array.array() must have a size <= 3" + self._char_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 256 for val in value)), \ + "The 'char_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 255]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._char_values = array.array('B', value) # type: ignore[assignment] + + @builtins.property + def float32_values(self) -> typing.Annotated[typing.Any, array.array[float]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'float32_values'.""" + return self._float32_values + + @float32_values.setter + def float32_values(self, value: typing.Union[array.array[float], collections.abc.Sequence[float]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'f', \ + "The 'float32_values' array.array() must have the type code of 'f'" + assert len(value) <= 3, \ + "The 'float32_values' array.array() must have a size <= 3" + self._float32_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, float) for v in value) and + all(not (val < -3.402823466e+38 or val > 3.402823466e+38) or math.isinf(val) for val in value)), \ + "The 'float32_values' field must be sequence with length <= 3 and each value of type float 'and each float in [-3.402823466e+38, 3.402823466e+38]'" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._float32_values = array.array('f', value) # type: ignore[assignment] + + @builtins.property + def float64_values(self) -> typing.Annotated[typing.Any, array.array[float]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'float64_values'.""" + return self._float64_values + + @float64_values.setter + def float64_values(self, value: typing.Union[array.array[float], collections.abc.Sequence[float]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'd', \ + "The 'float64_values' array.array() must have the type code of 'd'" + assert len(value) <= 3, \ + "The 'float64_values' array.array() must have a size <= 3" + self._float64_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, float) for v in value) and + all(not (val < -1.7976931348623157e+308 or val > 1.7976931348623157e+308) or math.isinf(val) for val in value)), \ + "The 'float64_values' field must be sequence with length <= 3 and each value of type float 'and each double in [-1.7976931348623157e+308, 1.7976931348623157e+308]'" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._float64_values = array.array('d', value) # type: ignore[assignment] + + @builtins.property + def int8_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'int8_values'.""" + return self._int8_values + + @int8_values.setter + def int8_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'b', \ + "The 'int8_values' array.array() must have the type code of 'b'" + assert len(value) <= 3, \ + "The 'int8_values' array.array() must have a size <= 3" + self._int8_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= -128 and val < 128 for val in value)), \ + "The 'int8_values' field must be sequence with length <= 3 and each value of type int and each integer in [-128, 127]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._int8_values = array.array('b', value) # type: ignore[assignment] + + @builtins.property + def uint8_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'uint8_values'.""" + return self._uint8_values + + @uint8_values.setter + def uint8_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'B', \ + "The 'uint8_values' array.array() must have the type code of 'B'" + assert len(value) <= 3, \ + "The 'uint8_values' array.array() must have a size <= 3" + self._uint8_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 256 for val in value)), \ + "The 'uint8_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 255]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._uint8_values = array.array('B', value) # type: ignore[assignment] + + @builtins.property + def int16_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'int16_values'.""" + return self._int16_values + + @int16_values.setter + def int16_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'h', \ + "The 'int16_values' array.array() must have the type code of 'h'" + assert len(value) <= 3, \ + "The 'int16_values' array.array() must have a size <= 3" + self._int16_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= -32768 and val < 32768 for val in value)), \ + "The 'int16_values' field must be sequence with length <= 3 and each value of type int and each integer in [-32768, 32767]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._int16_values = array.array('h', value) # type: ignore[assignment] + + @builtins.property + def uint16_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'uint16_values'.""" + return self._uint16_values + + @uint16_values.setter + def uint16_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'H', \ + "The 'uint16_values' array.array() must have the type code of 'H'" + assert len(value) <= 3, \ + "The 'uint16_values' array.array() must have a size <= 3" + self._uint16_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 65536 for val in value)), \ + "The 'uint16_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 65535]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._uint16_values = array.array('H', value) # type: ignore[assignment] + + @builtins.property + def int32_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'int32_values'.""" + return self._int32_values + + @int32_values.setter + def int32_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'i', \ + "The 'int32_values' array.array() must have the type code of 'i'" + assert len(value) <= 3, \ + "The 'int32_values' array.array() must have a size <= 3" + self._int32_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= -2147483648 and val < 2147483648 for val in value)), \ + "The 'int32_values' field must be sequence with length <= 3 and each value of type int and each integer in [-2147483648, 2147483647]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._int32_values = array.array('i', value) # type: ignore[assignment] + + @builtins.property + def uint32_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'uint32_values'.""" + return self._uint32_values + + @uint32_values.setter + def uint32_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'I', \ + "The 'uint32_values' array.array() must have the type code of 'I'" + assert len(value) <= 3, \ + "The 'uint32_values' array.array() must have a size <= 3" + self._uint32_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 4294967296 for val in value)), \ + "The 'uint32_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 4294967295]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._uint32_values = array.array('I', value) # type: ignore[assignment] + + @builtins.property + def int64_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'int64_values'.""" + return self._int64_values + + @int64_values.setter + def int64_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'q', \ + "The 'int64_values' array.array() must have the type code of 'q'" + assert len(value) <= 3, \ + "The 'int64_values' array.array() must have a size <= 3" + self._int64_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= -9223372036854775808 and val < 9223372036854775808 for val in value)), \ + "The 'int64_values' field must be sequence with length <= 3 and each value of type int and each integer in [-9223372036854775808, 9223372036854775807]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._int64_values = array.array('q', value) # type: ignore[assignment] + + @builtins.property + def uint64_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'uint64_values'.""" + return self._uint64_values + + @uint64_values.setter + def uint64_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'Q', \ + "The 'uint64_values' array.array() must have the type code of 'Q'" + assert len(value) <= 3, \ + "The 'uint64_values' array.array() must have a size <= 3" + self._uint64_values = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 18446744073709551616 for val in value)), \ + "The 'uint64_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 18446744073709551615]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._uint64_values = array.array('Q', value) # type: ignore[assignment] + + @builtins.property + def string_values(self) -> collections.abc.Sequence[str]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'string_values'.""" + return self._string_values + + @string_values.setter + def string_values(self, value: collections.abc.Sequence[str]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, str) for v in value) and + True), \ + "The 'string_values' field must be sequence with length <= 3 and each value of type str" + self._string_values = value + + @builtins.property + def basic_types_values(self) -> collections.abc.Sequence[BasicTypes]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'basic_types_values'.""" + return self._basic_types_values + + @basic_types_values.setter + def basic_types_values(self, value: collections.abc.Sequence[BasicTypes]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + from rosidl_generator_py.msg import BasicTypes + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, BasicTypes) for v in value) and + True), \ + "The 'basic_types_values' field must be sequence with length <= 3 and each value of type BasicTypes" + self._basic_types_values = value + + @builtins.property + def constants_values(self) -> collections.abc.Sequence[Constants]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'constants_values'.""" + return self._constants_values + + @constants_values.setter + def constants_values(self, value: collections.abc.Sequence[Constants]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + from rosidl_generator_py.msg import Constants + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, Constants) for v in value) and + True), \ + "The 'constants_values' field must be sequence with length <= 3 and each value of type Constants" + self._constants_values = value + + @builtins.property + def defaults_values(self) -> collections.abc.Sequence[Defaults]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'defaults_values'.""" + return self._defaults_values + + @defaults_values.setter + def defaults_values(self, value: collections.abc.Sequence[Defaults]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + from rosidl_generator_py.msg import Defaults + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, Defaults) for v in value) and + True), \ + "The 'defaults_values' field must be sequence with length <= 3 and each value of type Defaults" + self._defaults_values = value + + @builtins.property + def bool_values_default(self) -> collections.abc.Sequence[bool]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'bool_values_default'.""" + return self._bool_values_default + + @bool_values_default.setter + def bool_values_default(self, value: collections.abc.Sequence[bool]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, bool) for v in value) and + True), \ + "The 'bool_values_default' field must be sequence with length <= 3 and each value of type bool" + self._bool_values_default = value + + @builtins.property + def byte_values_default(self) -> collections.abc.Sequence[bytes]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'byte_values_default'.""" + return self._byte_values_default + + @byte_values_default.setter + def byte_values_default(self, value: collections.abc.Sequence[bytes]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, bytes) for v in value) and + True), \ + "The 'byte_values_default' field must be sequence with length <= 3 and each value of type bytes" + self._byte_values_default = value + + @builtins.property + def char_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'char_values_default'.""" + return self._char_values_default + + @char_values_default.setter + def char_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'B', \ + "The 'char_values_default' array.array() must have the type code of 'B'" + assert len(value) <= 3, \ + "The 'char_values_default' array.array() must have a size <= 3" + self._char_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 256 for val in value)), \ + "The 'char_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 255]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._char_values_default = array.array('B', value) # type: ignore[assignment] + + @builtins.property + def float32_values_default(self) -> typing.Annotated[typing.Any, array.array[float]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'float32_values_default'.""" + return self._float32_values_default + + @float32_values_default.setter + def float32_values_default(self, value: typing.Union[array.array[float], collections.abc.Sequence[float]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'f', \ + "The 'float32_values_default' array.array() must have the type code of 'f'" + assert len(value) <= 3, \ + "The 'float32_values_default' array.array() must have a size <= 3" + self._float32_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, float) for v in value) and + all(not (val < -3.402823466e+38 or val > 3.402823466e+38) or math.isinf(val) for val in value)), \ + "The 'float32_values_default' field must be sequence with length <= 3 and each value of type float 'and each float in [-3.402823466e+38, 3.402823466e+38]'" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._float32_values_default = array.array('f', value) # type: ignore[assignment] + + @builtins.property + def float64_values_default(self) -> typing.Annotated[typing.Any, array.array[float]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'float64_values_default'.""" + return self._float64_values_default + + @float64_values_default.setter + def float64_values_default(self, value: typing.Union[array.array[float], collections.abc.Sequence[float]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'd', \ + "The 'float64_values_default' array.array() must have the type code of 'd'" + assert len(value) <= 3, \ + "The 'float64_values_default' array.array() must have a size <= 3" + self._float64_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, float) for v in value) and + all(not (val < -1.7976931348623157e+308 or val > 1.7976931348623157e+308) or math.isinf(val) for val in value)), \ + "The 'float64_values_default' field must be sequence with length <= 3 and each value of type float 'and each double in [-1.7976931348623157e+308, 1.7976931348623157e+308]'" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._float64_values_default = array.array('d', value) # type: ignore[assignment] + + @builtins.property + def int8_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'int8_values_default'.""" + return self._int8_values_default + + @int8_values_default.setter + def int8_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'b', \ + "The 'int8_values_default' array.array() must have the type code of 'b'" + assert len(value) <= 3, \ + "The 'int8_values_default' array.array() must have a size <= 3" + self._int8_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= -128 and val < 128 for val in value)), \ + "The 'int8_values_default' field must be sequence with length <= 3 and each value of type int and each integer in [-128, 127]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._int8_values_default = array.array('b', value) # type: ignore[assignment] + + @builtins.property + def uint8_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'uint8_values_default'.""" + return self._uint8_values_default + + @uint8_values_default.setter + def uint8_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'B', \ + "The 'uint8_values_default' array.array() must have the type code of 'B'" + assert len(value) <= 3, \ + "The 'uint8_values_default' array.array() must have a size <= 3" + self._uint8_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 256 for val in value)), \ + "The 'uint8_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 255]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._uint8_values_default = array.array('B', value) # type: ignore[assignment] + + @builtins.property + def int16_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'int16_values_default'.""" + return self._int16_values_default + + @int16_values_default.setter + def int16_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'h', \ + "The 'int16_values_default' array.array() must have the type code of 'h'" + assert len(value) <= 3, \ + "The 'int16_values_default' array.array() must have a size <= 3" + self._int16_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= -32768 and val < 32768 for val in value)), \ + "The 'int16_values_default' field must be sequence with length <= 3 and each value of type int and each integer in [-32768, 32767]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._int16_values_default = array.array('h', value) # type: ignore[assignment] + + @builtins.property + def uint16_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'uint16_values_default'.""" + return self._uint16_values_default + + @uint16_values_default.setter + def uint16_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'H', \ + "The 'uint16_values_default' array.array() must have the type code of 'H'" + assert len(value) <= 3, \ + "The 'uint16_values_default' array.array() must have a size <= 3" + self._uint16_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 65536 for val in value)), \ + "The 'uint16_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 65535]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._uint16_values_default = array.array('H', value) # type: ignore[assignment] + + @builtins.property + def int32_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'int32_values_default'.""" + return self._int32_values_default + + @int32_values_default.setter + def int32_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'i', \ + "The 'int32_values_default' array.array() must have the type code of 'i'" + assert len(value) <= 3, \ + "The 'int32_values_default' array.array() must have a size <= 3" + self._int32_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= -2147483648 and val < 2147483648 for val in value)), \ + "The 'int32_values_default' field must be sequence with length <= 3 and each value of type int and each integer in [-2147483648, 2147483647]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._int32_values_default = array.array('i', value) # type: ignore[assignment] + + @builtins.property + def uint32_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'uint32_values_default'.""" + return self._uint32_values_default + + @uint32_values_default.setter + def uint32_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'I', \ + "The 'uint32_values_default' array.array() must have the type code of 'I'" + assert len(value) <= 3, \ + "The 'uint32_values_default' array.array() must have a size <= 3" + self._uint32_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 4294967296 for val in value)), \ + "The 'uint32_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 4294967295]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._uint32_values_default = array.array('I', value) # type: ignore[assignment] + + @builtins.property + def int64_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'int64_values_default'.""" + return self._int64_values_default + + @int64_values_default.setter + def int64_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'q', \ + "The 'int64_values_default' array.array() must have the type code of 'q'" + assert len(value) <= 3, \ + "The 'int64_values_default' array.array() must have a size <= 3" + self._int64_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= -9223372036854775808 and val < 9223372036854775808 for val in value)), \ + "The 'int64_values_default' field must be sequence with length <= 3 and each value of type int and each integer in [-9223372036854775808, 9223372036854775807]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._int64_values_default = array.array('q', value) # type: ignore[assignment] + + @builtins.property + def uint64_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'uint64_values_default'.""" + return self._uint64_values_default + + @uint64_values_default.setter + def uint64_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + if isinstance(value, array.array): + assert value.typecode == 'Q', \ + "The 'uint64_values_default' array.array() must have the type code of 'Q'" + assert len(value) <= 3, \ + "The 'uint64_values_default' array.array() must have a size <= 3" + self._uint64_values_default = value + return + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, int) for v in value) and + all(val >= 0 and val < 18446744073709551616 for val in value)), \ + "The 'uint64_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 18446744073709551615]" + # type ignore below fixed in mypy 1.17+ see mypy#19421 + self._uint64_values_default = array.array('Q', value) # type: ignore[assignment] + + @builtins.property + def string_values_default(self) -> collections.abc.Sequence[str]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 + """Message field 'string_values_default'.""" + return self._string_values_default + + @string_values_default.setter + def string_values_default(self, value: collections.abc.Sequence[str]) -> None: + + from collections.abc import Set + if isinstance(value, Set): + import warnings + warnings.warn( + 'Using set or subclass of set is deprecated,' + ' please use a subclass of collections.abc.Sequence like list', + DeprecationWarning) + if self._check_fields: + from collections.abc import Sequence + from collections import UserString + assert \ + ((isinstance(value, Sequence) or + isinstance(value, Set)) and + not isinstance(value, str) and + not isinstance(value, UserString) and + len(value) <= 3 and + all(isinstance(v, str) for v in value) and + True), \ + "The 'string_values_default' field must be sequence with length <= 3 and each value of type str" + self._string_values_default = value + + @builtins.property + def alignment_check(self) -> int: + """Message field 'alignment_check'.""" + return self._alignment_check + + @alignment_check.setter + def alignment_check(self, value: int) -> None: + + if self._check_fields: + assert \ + isinstance(value, int), \ + "The 'alignment_check' field must be of type 'int'" + assert value >= -2147483648 and value < 2147483648, \ + "The 'alignment_check' field must be an unsigned integer in [-2147483648, 2147483647]" + self._alignment_check = value From 85ec905612ba8299133ace8ca9fb8945441200fb Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Sat, 31 Jan 2026 20:43:30 -0800 Subject: [PATCH 2/6] move check fields generatoin into generate_py_impl Signed-off-by: Michael Carlstrom --- .../msg/_bounded_sequences.py | 1577 ----------------- rosidl_generator_py/resource/_msg.py.em | 157 +- .../rosidl_generator_py/generate_py_impl.py | 240 +++ 3 files changed, 242 insertions(+), 1732 deletions(-) delete mode 100644 build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_bounded_sequences.py diff --git a/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_bounded_sequences.py b/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_bounded_sequences.py deleted file mode 100644 index 5c3aee8b..00000000 --- a/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_bounded_sequences.py +++ /dev/null @@ -1,1577 +0,0 @@ -# generated from rosidl_generator_py/resource/_idl.py.em -# with input from rosidl_generator_py:msg/BoundedSequences.idl -# generated code does not contain a copyright notice - -from __future__ import annotations - -import collections.abc -from os import getenv -import typing - -import rosidl_pycommon.interface_base_classes - -# This is being done at the module level and not on the instance level to avoid looking -# for the same variable multiple times on each instance. This variable is not supposed to -# change during runtime so it makes sense to only look for it once. -ros_python_check_fields = getenv('ROS_PYTHON_CHECK_FIELDS', default='') - - -if typing.TYPE_CHECKING: - from rosidl_generator_py.msg import Constants - from ctypes import Structure - - class PyCapsule(Structure): - pass # don't need to define the full structure - from rosidl_generator_py.msg import BasicTypes - from rosidl_generator_py.msg import Defaults - - -# Import statements for member types - -# Member 'char_values' -# Member 'float32_values' -# Member 'float64_values' -# Member 'int8_values' -# Member 'uint8_values' -# Member 'int16_values' -# Member 'uint16_values' -# Member 'int32_values' -# Member 'uint32_values' -# Member 'int64_values' -# Member 'uint64_values' -# Member 'char_values_default' -# Member 'float32_values_default' -# Member 'float64_values_default' -# Member 'int8_values_default' -# Member 'uint8_values_default' -# Member 'int16_values_default' -# Member 'uint16_values_default' -# Member 'int32_values_default' -# Member 'uint32_values_default' -# Member 'int64_values_default' -# Member 'uint64_values_default' -import array # noqa: E402, I100 - -import builtins # noqa: E402, I100 - -import math # noqa: E402, I100 - -import rosidl_parser.definition # noqa: E402, I100 - - -class Metaclass_BoundedSequences(rosidl_pycommon.interface_base_classes.MessageTypeSupportMeta): - """Metaclass of message 'BoundedSequences'.""" - - _CREATE_ROS_MESSAGE: typing.ClassVar[typing.Optional[PyCapsule]] = None - _CONVERT_FROM_PY: typing.ClassVar[typing.Optional[PyCapsule]] = None - _CONVERT_TO_PY: typing.ClassVar[typing.Optional[PyCapsule]] = None - _DESTROY_ROS_MESSAGE: typing.ClassVar[typing.Optional[PyCapsule]] = None - _TYPE_SUPPORT: typing.ClassVar[typing.Optional[PyCapsule]] = None - - class BoundedSequencesConstants(typing.TypedDict): - pass - - __constants: BoundedSequencesConstants = { - } - - @classmethod - def __import_type_support__(cls) -> None: - try: - from rosidl_generator_py import import_type_support # type: ignore[attr-defined] - module = import_type_support('rosidl_generator_py') - except ImportError: - import logging - import traceback - logger = logging.getLogger( - 'rosidl_generator_py.msg.BoundedSequences') - logger.debug( - 'Failed to import needed modules for type support:\n' + - traceback.format_exc()) - else: - cls._CREATE_ROS_MESSAGE = module.create_ros_message_msg__msg__bounded_sequences - cls._CONVERT_FROM_PY = module.convert_from_py_msg__msg__bounded_sequences - cls._CONVERT_TO_PY = module.convert_to_py_msg__msg__bounded_sequences - cls._TYPE_SUPPORT = module.type_support_msg__msg__bounded_sequences - cls._DESTROY_ROS_MESSAGE = module.destroy_ros_message_msg__msg__bounded_sequences - - from rosidl_generator_py.msg import BasicTypes - if BasicTypes._TYPE_SUPPORT is None: - BasicTypes.__import_type_support__() - - from rosidl_generator_py.msg import Constants - if Constants._TYPE_SUPPORT is None: - Constants.__import_type_support__() - - from rosidl_generator_py.msg import Defaults - if Defaults._TYPE_SUPPORT is None: - Defaults.__import_type_support__() - - @classmethod - def __prepare__(metacls, name: str, bases: tuple[type[typing.Any], ...], /, **kwds: typing.Any) -> collections.abc.MutableMapping[str, object]: - # list constant names here so that they appear in the help text of - # the message class under "Data and other attributes defined here:" - # as well as populate each message instance - return { - 'BOOL_VALUES_DEFAULT__DEFAULT': [False, True, False], - 'BYTE_VALUES_DEFAULT__DEFAULT': [b'\x00', b'\x01', b'\xff'], - 'CHAR_VALUES_DEFAULT__DEFAULT': array.array('B', (0, 1, 127, )), - 'FLOAT32_VALUES_DEFAULT__DEFAULT': array.array('f', (1.125, 0.0, -1.125, )), - 'FLOAT64_VALUES_DEFAULT__DEFAULT': array.array('d', (3.1415, 0.0, -3.1415, )), - 'INT8_VALUES_DEFAULT__DEFAULT': array.array('b', (0, 127, -128, )), - 'UINT8_VALUES_DEFAULT__DEFAULT': array.array('B', (0, 1, 255, )), - 'INT16_VALUES_DEFAULT__DEFAULT': array.array('h', (0, 32767, -32768, )), - 'UINT16_VALUES_DEFAULT__DEFAULT': array.array('H', (0, 1, 65535, )), - 'INT32_VALUES_DEFAULT__DEFAULT': array.array('i', (0, 2147483647, -2147483648, )), - 'UINT32_VALUES_DEFAULT__DEFAULT': array.array('I', (0, 1, 4294967295, )), - 'INT64_VALUES_DEFAULT__DEFAULT': array.array('q', (0, 9223372036854775807, -9223372036854775808, )), - 'UINT64_VALUES_DEFAULT__DEFAULT': array.array('Q', (0, 1, 18446744073709551615, )), - 'STRING_VALUES_DEFAULT__DEFAULT': ['', 'max value', 'min value'], - } - - @property - def BOOL_VALUES_DEFAULT__DEFAULT(cls) -> list[bool]: - """Return default value for message field 'bool_values_default'.""" - return [False, True, False] - - @property - def BYTE_VALUES_DEFAULT__DEFAULT(cls) -> list[bytes]: - """Return default value for message field 'byte_values_default'.""" - return [b'\x00', b'\x01', b'\xff'] - - @property - def CHAR_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: - """Return default value for message field 'char_values_default'.""" - return array.array('B', (0, 1, 127, )) - - @property - def FLOAT32_VALUES_DEFAULT__DEFAULT(cls) -> array.array[float]: - """Return default value for message field 'float32_values_default'.""" - return array.array('f', (1.125, 0.0, -1.125, )) - - @property - def FLOAT64_VALUES_DEFAULT__DEFAULT(cls) -> array.array[float]: - """Return default value for message field 'float64_values_default'.""" - return array.array('d', (3.1415, 0.0, -3.1415, )) - - @property - def INT8_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: - """Return default value for message field 'int8_values_default'.""" - return array.array('b', (0, 127, -128, )) - - @property - def UINT8_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: - """Return default value for message field 'uint8_values_default'.""" - return array.array('B', (0, 1, 255, )) - - @property - def INT16_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: - """Return default value for message field 'int16_values_default'.""" - return array.array('h', (0, 32767, -32768, )) - - @property - def UINT16_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: - """Return default value for message field 'uint16_values_default'.""" - return array.array('H', (0, 1, 65535, )) - - @property - def INT32_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: - """Return default value for message field 'int32_values_default'.""" - return array.array('i', (0, 2147483647, -2147483648, )) - - @property - def UINT32_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: - """Return default value for message field 'uint32_values_default'.""" - return array.array('I', (0, 1, 4294967295, )) - - @property - def INT64_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: - """Return default value for message field 'int64_values_default'.""" - return array.array('q', (0, 9223372036854775807, -9223372036854775808, )) - - @property - def UINT64_VALUES_DEFAULT__DEFAULT(cls) -> array.array[int]: - """Return default value for message field 'uint64_values_default'.""" - return array.array('Q', (0, 1, 18446744073709551615, )) - - @property - def STRING_VALUES_DEFAULT__DEFAULT(cls) -> list[str]: - """Return default value for message field 'string_values_default'.""" - return ['', 'max value', 'min value'] - - -class BoundedSequences(rosidl_pycommon.interface_base_classes.BaseMessage, metaclass=Metaclass_BoundedSequences): - """Message class 'BoundedSequences'.""" - - __slots__ = [ - '_bool_values', - '_byte_values', - '_char_values', - '_float32_values', - '_float64_values', - '_int8_values', - '_uint8_values', - '_int16_values', - '_uint16_values', - '_int32_values', - '_uint32_values', - '_int64_values', - '_uint64_values', - '_string_values', - '_basic_types_values', - '_constants_values', - '_defaults_values', - '_bool_values_default', - '_byte_values_default', - '_char_values_default', - '_float32_values_default', - '_float64_values_default', - '_int8_values_default', - '_uint8_values_default', - '_int16_values_default', - '_uint16_values_default', - '_int32_values_default', - '_uint32_values_default', - '_int64_values_default', - '_uint64_values_default', - '_string_values_default', - '_alignment_check', - '_check_fields', - ] - - _fields_and_field_types: dict[str, str] = { - 'bool_values': 'sequence', - 'byte_values': 'sequence', - 'char_values': 'sequence', - 'float32_values': 'sequence', - 'float64_values': 'sequence', - 'int8_values': 'sequence', - 'uint8_values': 'sequence', - 'int16_values': 'sequence', - 'uint16_values': 'sequence', - 'int32_values': 'sequence', - 'uint32_values': 'sequence', - 'int64_values': 'sequence', - 'uint64_values': 'sequence', - 'string_values': 'sequence', - 'basic_types_values': 'sequence', - 'constants_values': 'sequence', - 'defaults_values': 'sequence', - 'bool_values_default': 'sequence', - 'byte_values_default': 'sequence', - 'char_values_default': 'sequence', - 'float32_values_default': 'sequence', - 'float64_values_default': 'sequence', - 'int8_values_default': 'sequence', - 'uint8_values_default': 'sequence', - 'int16_values_default': 'sequence', - 'uint16_values_default': 'sequence', - 'int32_values_default': 'sequence', - 'uint32_values_default': 'sequence', - 'int64_values_default': 'sequence', - 'uint64_values_default': 'sequence', - 'string_values_default': 'sequence', - 'alignment_check': 'int32', - } - - # This attribute is used to store an rosidl_parser.definition variable - # related to the data type of each of the components the message. - SLOT_TYPES: tuple[rosidl_parser.definition.AbstractType, ...] = ( - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('boolean'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('octet'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint8'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('float'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('double'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int8'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint8'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int16'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint16'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int32'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint32'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int64'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint64'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.UnboundedString(), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.NamespacedType(['rosidl_generator_py', 'msg'], 'BasicTypes'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.NamespacedType(['rosidl_generator_py', 'msg'], 'Constants'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.NamespacedType(['rosidl_generator_py', 'msg'], 'Defaults'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('boolean'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('octet'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint8'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('float'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('double'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int8'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint8'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int16'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint16'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int32'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint32'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('int64'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.BasicType('uint64'), 3), # noqa: E501 - rosidl_parser.definition.BoundedSequence(rosidl_parser.definition.UnboundedString(), 3), # noqa: E501 - rosidl_parser.definition.BasicType('int32'), # noqa: E501 - ) - - def __init__(self, *, - bool_values: typing.Optional[collections.abc.Sequence[bool]] = None, # noqa: E501 - byte_values: typing.Optional[collections.abc.Sequence[bytes]] = None, # noqa: E501 - char_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - float32_values: typing.Optional[typing.Union[array.array[float], collections.abc.Sequence[float]]] = None, # noqa: E501 - float64_values: typing.Optional[typing.Union[array.array[float], collections.abc.Sequence[float]]] = None, # noqa: E501 - int8_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - uint8_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - int16_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - uint16_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - int32_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - uint32_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - int64_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - uint64_values: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - string_values: typing.Optional[collections.abc.Sequence[str]] = None, # noqa: E501 - basic_types_values: typing.Optional[collections.abc.Sequence[BasicTypes]] = None, # noqa: E501 - constants_values: typing.Optional[collections.abc.Sequence[Constants]] = None, # noqa: E501 - defaults_values: typing.Optional[collections.abc.Sequence[Defaults]] = None, # noqa: E501 - bool_values_default: typing.Optional[collections.abc.Sequence[bool]] = None, # noqa: E501 - byte_values_default: typing.Optional[collections.abc.Sequence[bytes]] = None, # noqa: E501 - char_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - float32_values_default: typing.Optional[typing.Union[array.array[float], collections.abc.Sequence[float]]] = None, # noqa: E501 - float64_values_default: typing.Optional[typing.Union[array.array[float], collections.abc.Sequence[float]]] = None, # noqa: E501 - int8_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - uint8_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - int16_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - uint16_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - int32_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - uint32_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - int64_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - uint64_values_default: typing.Optional[typing.Union[array.array[int], collections.abc.Sequence[int]]] = None, # noqa: E501 - string_values_default: typing.Optional[collections.abc.Sequence[str]] = None, # noqa: E501 - alignment_check: typing.Optional[int] = None, # noqa: E501 - check_fields: typing.Optional[bool] = None) -> None: - if check_fields is not None: - self._check_fields = check_fields - else: - self._check_fields = ros_python_check_fields == '1' - self.bool_values = bool_values if bool_values is not None else [] - self.byte_values = byte_values if byte_values is not None else [] - self.char_values = char_values if char_values is not None else array.array('B', []) - self.float32_values = float32_values if float32_values is not None else array.array('f', []) - self.float64_values = float64_values if float64_values is not None else array.array('d', []) - self.int8_values = int8_values if int8_values is not None else array.array('b', []) - self.uint8_values = uint8_values if uint8_values is not None else array.array('B', []) - self.int16_values = int16_values if int16_values is not None else array.array('h', []) - self.uint16_values = uint16_values if uint16_values is not None else array.array('H', []) - self.int32_values = int32_values if int32_values is not None else array.array('i', []) - self.uint32_values = uint32_values if uint32_values is not None else array.array('I', []) - self.int64_values = int64_values if int64_values is not None else array.array('q', []) - self.uint64_values = uint64_values if uint64_values is not None else array.array('Q', []) - self.string_values = string_values if string_values is not None else [] - self.basic_types_values = basic_types_values if basic_types_values is not None else [] - self.constants_values = constants_values if constants_values is not None else [] - self.defaults_values = defaults_values if defaults_values is not None else [] - self.bool_values_default = bool_values_default if bool_values_default is not None else BoundedSequences.BOOL_VALUES_DEFAULT__DEFAULT - self.byte_values_default = byte_values_default if byte_values_default is not None else BoundedSequences.BYTE_VALUES_DEFAULT__DEFAULT - self.char_values_default = char_values_default if char_values_default is not None else BoundedSequences.CHAR_VALUES_DEFAULT__DEFAULT - self.float32_values_default = float32_values_default if float32_values_default is not None else BoundedSequences.FLOAT32_VALUES_DEFAULT__DEFAULT - self.float64_values_default = float64_values_default if float64_values_default is not None else BoundedSequences.FLOAT64_VALUES_DEFAULT__DEFAULT - self.int8_values_default = int8_values_default if int8_values_default is not None else BoundedSequences.INT8_VALUES_DEFAULT__DEFAULT - self.uint8_values_default = uint8_values_default if uint8_values_default is not None else BoundedSequences.UINT8_VALUES_DEFAULT__DEFAULT - self.int16_values_default = int16_values_default if int16_values_default is not None else BoundedSequences.INT16_VALUES_DEFAULT__DEFAULT - self.uint16_values_default = uint16_values_default if uint16_values_default is not None else BoundedSequences.UINT16_VALUES_DEFAULT__DEFAULT - self.int32_values_default = int32_values_default if int32_values_default is not None else BoundedSequences.INT32_VALUES_DEFAULT__DEFAULT - self.uint32_values_default = uint32_values_default if uint32_values_default is not None else BoundedSequences.UINT32_VALUES_DEFAULT__DEFAULT - self.int64_values_default = int64_values_default if int64_values_default is not None else BoundedSequences.INT64_VALUES_DEFAULT__DEFAULT - self.uint64_values_default = uint64_values_default if uint64_values_default is not None else BoundedSequences.UINT64_VALUES_DEFAULT__DEFAULT - self.string_values_default = string_values_default if string_values_default is not None else BoundedSequences.STRING_VALUES_DEFAULT__DEFAULT - self.alignment_check = alignment_check if alignment_check is not None else int() - - def __repr__(self) -> str: - typename = self.__class__.__module__.split('.') - typename.pop() - typename.append(self.__class__.__name__) - args: list[str] = [] - for s, t in zip(self.get_fields_and_field_types().keys(), self.SLOT_TYPES): - field = getattr(self, s) - fieldstr = repr(field) - # We use Python array type for fields that can be directly stored - # in them, and "normal" sequences for everything else. If it is - # a type that we store in an array, strip off the 'array' portion. - if ( - isinstance(t, rosidl_parser.definition.AbstractSequence) and - isinstance(t.value_type, rosidl_parser.definition.BasicType) and - t.value_type.typename in ['float', 'double', 'int8', 'uint8', 'int16', 'uint16', 'int32', 'uint32', 'int64', 'uint64'] - ): - if len(field) == 0: - fieldstr = '[]' - else: - if self._check_fields: - assert fieldstr.startswith('array(') - prefix = "array('X', " - suffix = ')' - fieldstr = fieldstr[len(prefix):-len(suffix)] - args.append(s + '=' + fieldstr) - return '%s(%s)' % ('.'.join(typename), ', '.join(args)) - - def __eq__(self, other: object) -> bool: - if not isinstance(other, BoundedSequences): - return False - if self.bool_values != other.bool_values: - return False - if self.byte_values != other.byte_values: - return False - if self.char_values != other.char_values: - return False - if self.float32_values != other.float32_values: - return False - if self.float64_values != other.float64_values: - return False - if self.int8_values != other.int8_values: - return False - if self.uint8_values != other.uint8_values: - return False - if self.int16_values != other.int16_values: - return False - if self.uint16_values != other.uint16_values: - return False - if self.int32_values != other.int32_values: - return False - if self.uint32_values != other.uint32_values: - return False - if self.int64_values != other.int64_values: - return False - if self.uint64_values != other.uint64_values: - return False - if self.string_values != other.string_values: - return False - if self.basic_types_values != other.basic_types_values: - return False - if self.constants_values != other.constants_values: - return False - if self.defaults_values != other.defaults_values: - return False - if self.bool_values_default != other.bool_values_default: - return False - if self.byte_values_default != other.byte_values_default: - return False - if self.char_values_default != other.char_values_default: - return False - if self.float32_values_default != other.float32_values_default: - return False - if self.float64_values_default != other.float64_values_default: - return False - if self.int8_values_default != other.int8_values_default: - return False - if self.uint8_values_default != other.uint8_values_default: - return False - if self.int16_values_default != other.int16_values_default: - return False - if self.uint16_values_default != other.uint16_values_default: - return False - if self.int32_values_default != other.int32_values_default: - return False - if self.uint32_values_default != other.uint32_values_default: - return False - if self.int64_values_default != other.int64_values_default: - return False - if self.uint64_values_default != other.uint64_values_default: - return False - if self.string_values_default != other.string_values_default: - return False - if self.alignment_check != other.alignment_check: - return False - return True - - @classmethod - def get_fields_and_field_types(cls) -> dict[str, str]: - from copy import copy - return copy(cls._fields_and_field_types) - - @builtins.property - def bool_values(self) -> collections.abc.Sequence[bool]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'bool_values'.""" - return self._bool_values - - @bool_values.setter - def bool_values(self, value: collections.abc.Sequence[bool]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, bool) for v in value) and - True), \ - "The 'bool_values' field must be sequence with length <= 3 and each value of type bool" - self._bool_values = value - - @builtins.property - def byte_values(self) -> collections.abc.Sequence[bytes]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'byte_values'.""" - return self._byte_values - - @byte_values.setter - def byte_values(self, value: collections.abc.Sequence[bytes]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, bytes) for v in value) and - True), \ - "The 'byte_values' field must be sequence with length <= 3 and each value of type bytes" - self._byte_values = value - - @builtins.property - def char_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'char_values'.""" - return self._char_values - - @char_values.setter - def char_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'B', \ - "The 'char_values' array.array() must have the type code of 'B'" - assert len(value) <= 3, \ - "The 'char_values' array.array() must have a size <= 3" - self._char_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 256 for val in value)), \ - "The 'char_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 255]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._char_values = array.array('B', value) # type: ignore[assignment] - - @builtins.property - def float32_values(self) -> typing.Annotated[typing.Any, array.array[float]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'float32_values'.""" - return self._float32_values - - @float32_values.setter - def float32_values(self, value: typing.Union[array.array[float], collections.abc.Sequence[float]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'f', \ - "The 'float32_values' array.array() must have the type code of 'f'" - assert len(value) <= 3, \ - "The 'float32_values' array.array() must have a size <= 3" - self._float32_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, float) for v in value) and - all(not (val < -3.402823466e+38 or val > 3.402823466e+38) or math.isinf(val) for val in value)), \ - "The 'float32_values' field must be sequence with length <= 3 and each value of type float 'and each float in [-3.402823466e+38, 3.402823466e+38]'" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._float32_values = array.array('f', value) # type: ignore[assignment] - - @builtins.property - def float64_values(self) -> typing.Annotated[typing.Any, array.array[float]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'float64_values'.""" - return self._float64_values - - @float64_values.setter - def float64_values(self, value: typing.Union[array.array[float], collections.abc.Sequence[float]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'd', \ - "The 'float64_values' array.array() must have the type code of 'd'" - assert len(value) <= 3, \ - "The 'float64_values' array.array() must have a size <= 3" - self._float64_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, float) for v in value) and - all(not (val < -1.7976931348623157e+308 or val > 1.7976931348623157e+308) or math.isinf(val) for val in value)), \ - "The 'float64_values' field must be sequence with length <= 3 and each value of type float 'and each double in [-1.7976931348623157e+308, 1.7976931348623157e+308]'" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._float64_values = array.array('d', value) # type: ignore[assignment] - - @builtins.property - def int8_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'int8_values'.""" - return self._int8_values - - @int8_values.setter - def int8_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'b', \ - "The 'int8_values' array.array() must have the type code of 'b'" - assert len(value) <= 3, \ - "The 'int8_values' array.array() must have a size <= 3" - self._int8_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= -128 and val < 128 for val in value)), \ - "The 'int8_values' field must be sequence with length <= 3 and each value of type int and each integer in [-128, 127]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._int8_values = array.array('b', value) # type: ignore[assignment] - - @builtins.property - def uint8_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'uint8_values'.""" - return self._uint8_values - - @uint8_values.setter - def uint8_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'B', \ - "The 'uint8_values' array.array() must have the type code of 'B'" - assert len(value) <= 3, \ - "The 'uint8_values' array.array() must have a size <= 3" - self._uint8_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 256 for val in value)), \ - "The 'uint8_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 255]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._uint8_values = array.array('B', value) # type: ignore[assignment] - - @builtins.property - def int16_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'int16_values'.""" - return self._int16_values - - @int16_values.setter - def int16_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'h', \ - "The 'int16_values' array.array() must have the type code of 'h'" - assert len(value) <= 3, \ - "The 'int16_values' array.array() must have a size <= 3" - self._int16_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= -32768 and val < 32768 for val in value)), \ - "The 'int16_values' field must be sequence with length <= 3 and each value of type int and each integer in [-32768, 32767]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._int16_values = array.array('h', value) # type: ignore[assignment] - - @builtins.property - def uint16_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'uint16_values'.""" - return self._uint16_values - - @uint16_values.setter - def uint16_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'H', \ - "The 'uint16_values' array.array() must have the type code of 'H'" - assert len(value) <= 3, \ - "The 'uint16_values' array.array() must have a size <= 3" - self._uint16_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 65536 for val in value)), \ - "The 'uint16_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 65535]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._uint16_values = array.array('H', value) # type: ignore[assignment] - - @builtins.property - def int32_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'int32_values'.""" - return self._int32_values - - @int32_values.setter - def int32_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'i', \ - "The 'int32_values' array.array() must have the type code of 'i'" - assert len(value) <= 3, \ - "The 'int32_values' array.array() must have a size <= 3" - self._int32_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= -2147483648 and val < 2147483648 for val in value)), \ - "The 'int32_values' field must be sequence with length <= 3 and each value of type int and each integer in [-2147483648, 2147483647]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._int32_values = array.array('i', value) # type: ignore[assignment] - - @builtins.property - def uint32_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'uint32_values'.""" - return self._uint32_values - - @uint32_values.setter - def uint32_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'I', \ - "The 'uint32_values' array.array() must have the type code of 'I'" - assert len(value) <= 3, \ - "The 'uint32_values' array.array() must have a size <= 3" - self._uint32_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 4294967296 for val in value)), \ - "The 'uint32_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 4294967295]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._uint32_values = array.array('I', value) # type: ignore[assignment] - - @builtins.property - def int64_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'int64_values'.""" - return self._int64_values - - @int64_values.setter - def int64_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'q', \ - "The 'int64_values' array.array() must have the type code of 'q'" - assert len(value) <= 3, \ - "The 'int64_values' array.array() must have a size <= 3" - self._int64_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= -9223372036854775808 and val < 9223372036854775808 for val in value)), \ - "The 'int64_values' field must be sequence with length <= 3 and each value of type int and each integer in [-9223372036854775808, 9223372036854775807]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._int64_values = array.array('q', value) # type: ignore[assignment] - - @builtins.property - def uint64_values(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'uint64_values'.""" - return self._uint64_values - - @uint64_values.setter - def uint64_values(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'Q', \ - "The 'uint64_values' array.array() must have the type code of 'Q'" - assert len(value) <= 3, \ - "The 'uint64_values' array.array() must have a size <= 3" - self._uint64_values = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 18446744073709551616 for val in value)), \ - "The 'uint64_values' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 18446744073709551615]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._uint64_values = array.array('Q', value) # type: ignore[assignment] - - @builtins.property - def string_values(self) -> collections.abc.Sequence[str]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'string_values'.""" - return self._string_values - - @string_values.setter - def string_values(self, value: collections.abc.Sequence[str]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, str) for v in value) and - True), \ - "The 'string_values' field must be sequence with length <= 3 and each value of type str" - self._string_values = value - - @builtins.property - def basic_types_values(self) -> collections.abc.Sequence[BasicTypes]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'basic_types_values'.""" - return self._basic_types_values - - @basic_types_values.setter - def basic_types_values(self, value: collections.abc.Sequence[BasicTypes]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - from rosidl_generator_py.msg import BasicTypes - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, BasicTypes) for v in value) and - True), \ - "The 'basic_types_values' field must be sequence with length <= 3 and each value of type BasicTypes" - self._basic_types_values = value - - @builtins.property - def constants_values(self) -> collections.abc.Sequence[Constants]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'constants_values'.""" - return self._constants_values - - @constants_values.setter - def constants_values(self, value: collections.abc.Sequence[Constants]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - from rosidl_generator_py.msg import Constants - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, Constants) for v in value) and - True), \ - "The 'constants_values' field must be sequence with length <= 3 and each value of type Constants" - self._constants_values = value - - @builtins.property - def defaults_values(self) -> collections.abc.Sequence[Defaults]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'defaults_values'.""" - return self._defaults_values - - @defaults_values.setter - def defaults_values(self, value: collections.abc.Sequence[Defaults]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - from rosidl_generator_py.msg import Defaults - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, Defaults) for v in value) and - True), \ - "The 'defaults_values' field must be sequence with length <= 3 and each value of type Defaults" - self._defaults_values = value - - @builtins.property - def bool_values_default(self) -> collections.abc.Sequence[bool]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'bool_values_default'.""" - return self._bool_values_default - - @bool_values_default.setter - def bool_values_default(self, value: collections.abc.Sequence[bool]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, bool) for v in value) and - True), \ - "The 'bool_values_default' field must be sequence with length <= 3 and each value of type bool" - self._bool_values_default = value - - @builtins.property - def byte_values_default(self) -> collections.abc.Sequence[bytes]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'byte_values_default'.""" - return self._byte_values_default - - @byte_values_default.setter - def byte_values_default(self, value: collections.abc.Sequence[bytes]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, bytes) for v in value) and - True), \ - "The 'byte_values_default' field must be sequence with length <= 3 and each value of type bytes" - self._byte_values_default = value - - @builtins.property - def char_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'char_values_default'.""" - return self._char_values_default - - @char_values_default.setter - def char_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'B', \ - "The 'char_values_default' array.array() must have the type code of 'B'" - assert len(value) <= 3, \ - "The 'char_values_default' array.array() must have a size <= 3" - self._char_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 256 for val in value)), \ - "The 'char_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 255]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._char_values_default = array.array('B', value) # type: ignore[assignment] - - @builtins.property - def float32_values_default(self) -> typing.Annotated[typing.Any, array.array[float]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'float32_values_default'.""" - return self._float32_values_default - - @float32_values_default.setter - def float32_values_default(self, value: typing.Union[array.array[float], collections.abc.Sequence[float]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'f', \ - "The 'float32_values_default' array.array() must have the type code of 'f'" - assert len(value) <= 3, \ - "The 'float32_values_default' array.array() must have a size <= 3" - self._float32_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, float) for v in value) and - all(not (val < -3.402823466e+38 or val > 3.402823466e+38) or math.isinf(val) for val in value)), \ - "The 'float32_values_default' field must be sequence with length <= 3 and each value of type float 'and each float in [-3.402823466e+38, 3.402823466e+38]'" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._float32_values_default = array.array('f', value) # type: ignore[assignment] - - @builtins.property - def float64_values_default(self) -> typing.Annotated[typing.Any, array.array[float]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'float64_values_default'.""" - return self._float64_values_default - - @float64_values_default.setter - def float64_values_default(self, value: typing.Union[array.array[float], collections.abc.Sequence[float]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'd', \ - "The 'float64_values_default' array.array() must have the type code of 'd'" - assert len(value) <= 3, \ - "The 'float64_values_default' array.array() must have a size <= 3" - self._float64_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, float) for v in value) and - all(not (val < -1.7976931348623157e+308 or val > 1.7976931348623157e+308) or math.isinf(val) for val in value)), \ - "The 'float64_values_default' field must be sequence with length <= 3 and each value of type float 'and each double in [-1.7976931348623157e+308, 1.7976931348623157e+308]'" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._float64_values_default = array.array('d', value) # type: ignore[assignment] - - @builtins.property - def int8_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'int8_values_default'.""" - return self._int8_values_default - - @int8_values_default.setter - def int8_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'b', \ - "The 'int8_values_default' array.array() must have the type code of 'b'" - assert len(value) <= 3, \ - "The 'int8_values_default' array.array() must have a size <= 3" - self._int8_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= -128 and val < 128 for val in value)), \ - "The 'int8_values_default' field must be sequence with length <= 3 and each value of type int and each integer in [-128, 127]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._int8_values_default = array.array('b', value) # type: ignore[assignment] - - @builtins.property - def uint8_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'uint8_values_default'.""" - return self._uint8_values_default - - @uint8_values_default.setter - def uint8_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'B', \ - "The 'uint8_values_default' array.array() must have the type code of 'B'" - assert len(value) <= 3, \ - "The 'uint8_values_default' array.array() must have a size <= 3" - self._uint8_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 256 for val in value)), \ - "The 'uint8_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 255]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._uint8_values_default = array.array('B', value) # type: ignore[assignment] - - @builtins.property - def int16_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'int16_values_default'.""" - return self._int16_values_default - - @int16_values_default.setter - def int16_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'h', \ - "The 'int16_values_default' array.array() must have the type code of 'h'" - assert len(value) <= 3, \ - "The 'int16_values_default' array.array() must have a size <= 3" - self._int16_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= -32768 and val < 32768 for val in value)), \ - "The 'int16_values_default' field must be sequence with length <= 3 and each value of type int and each integer in [-32768, 32767]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._int16_values_default = array.array('h', value) # type: ignore[assignment] - - @builtins.property - def uint16_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'uint16_values_default'.""" - return self._uint16_values_default - - @uint16_values_default.setter - def uint16_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'H', \ - "The 'uint16_values_default' array.array() must have the type code of 'H'" - assert len(value) <= 3, \ - "The 'uint16_values_default' array.array() must have a size <= 3" - self._uint16_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 65536 for val in value)), \ - "The 'uint16_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 65535]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._uint16_values_default = array.array('H', value) # type: ignore[assignment] - - @builtins.property - def int32_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'int32_values_default'.""" - return self._int32_values_default - - @int32_values_default.setter - def int32_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'i', \ - "The 'int32_values_default' array.array() must have the type code of 'i'" - assert len(value) <= 3, \ - "The 'int32_values_default' array.array() must have a size <= 3" - self._int32_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= -2147483648 and val < 2147483648 for val in value)), \ - "The 'int32_values_default' field must be sequence with length <= 3 and each value of type int and each integer in [-2147483648, 2147483647]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._int32_values_default = array.array('i', value) # type: ignore[assignment] - - @builtins.property - def uint32_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'uint32_values_default'.""" - return self._uint32_values_default - - @uint32_values_default.setter - def uint32_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'I', \ - "The 'uint32_values_default' array.array() must have the type code of 'I'" - assert len(value) <= 3, \ - "The 'uint32_values_default' array.array() must have a size <= 3" - self._uint32_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 4294967296 for val in value)), \ - "The 'uint32_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 4294967295]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._uint32_values_default = array.array('I', value) # type: ignore[assignment] - - @builtins.property - def int64_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'int64_values_default'.""" - return self._int64_values_default - - @int64_values_default.setter - def int64_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'q', \ - "The 'int64_values_default' array.array() must have the type code of 'q'" - assert len(value) <= 3, \ - "The 'int64_values_default' array.array() must have a size <= 3" - self._int64_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= -9223372036854775808 and val < 9223372036854775808 for val in value)), \ - "The 'int64_values_default' field must be sequence with length <= 3 and each value of type int and each integer in [-9223372036854775808, 9223372036854775807]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._int64_values_default = array.array('q', value) # type: ignore[assignment] - - @builtins.property - def uint64_values_default(self) -> typing.Annotated[typing.Any, array.array[int]]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'uint64_values_default'.""" - return self._uint64_values_default - - @uint64_values_default.setter - def uint64_values_default(self, value: typing.Union[array.array[int], collections.abc.Sequence[int]]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - if isinstance(value, array.array): - assert value.typecode == 'Q', \ - "The 'uint64_values_default' array.array() must have the type code of 'Q'" - assert len(value) <= 3, \ - "The 'uint64_values_default' array.array() must have a size <= 3" - self._uint64_values_default = value - return - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, int) for v in value) and - all(val >= 0 and val < 18446744073709551616 for val in value)), \ - "The 'uint64_values_default' field must be sequence with length <= 3 and each value of type int and each unsigned integer in [0, 18446744073709551615]" - # type ignore below fixed in mypy 1.17+ see mypy#19421 - self._uint64_values_default = array.array('Q', value) # type: ignore[assignment] - - @builtins.property - def string_values_default(self) -> collections.abc.Sequence[str]: # typing.Annotated can be remove after mypy 1.16+ see mypy#3004 - """Message field 'string_values_default'.""" - return self._string_values_default - - @string_values_default.setter - def string_values_default(self, value: collections.abc.Sequence[str]) -> None: - - from collections.abc import Set - if isinstance(value, Set): - import warnings - warnings.warn( - 'Using set or subclass of set is deprecated,' - ' please use a subclass of collections.abc.Sequence like list', - DeprecationWarning) - if self._check_fields: - from collections.abc import Sequence - from collections import UserString - assert \ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and - len(value) <= 3 and - all(isinstance(v, str) for v in value) and - True), \ - "The 'string_values_default' field must be sequence with length <= 3 and each value of type str" - self._string_values_default = value - - @builtins.property - def alignment_check(self) -> int: - """Message field 'alignment_check'.""" - return self._alignment_check - - @alignment_check.setter - def alignment_check(self, value: int) -> None: - - if self._check_fields: - assert \ - isinstance(value, int), \ - "The 'alignment_check' field must be of type 'int'" - assert value >= -2147483648 and value < 2147483648, \ - "The 'alignment_check' field must be an unsigned integer in [-2147483648, 2147483647]" - self._alignment_check = value diff --git a/rosidl_generator_py/resource/_msg.py.em b/rosidl_generator_py/resource/_msg.py.em index 98285ecb..e5a86724 100644 --- a/rosidl_generator_py/resource/_msg.py.em +++ b/rosidl_generator_py/resource/_msg.py.em @@ -9,6 +9,7 @@ from rosidl_generator_py.generate_py_impl import get_type_annotation_default from rosidl_generator_py.generate_py_impl import get_setter_and_getter_type from rosidl_generator_py.generate_py_impl import SPECIAL_NESTED_BASIC_TYPES from rosidl_generator_py.generate_py_impl import value_to_py +from rosidl_generator_py.generate_py_impl import generate_check_fields from rosidl_parser.definition import AbstractGenericString from rosidl_parser.definition import AbstractNestedType from rosidl_parser.definition import AbstractSequence @@ -504,161 +505,7 @@ if isinstance(member.type, (Array, AbstractSequence)): ' please use a subclass of collections.abc.Sequence like list', DeprecationWarning) @[ end if]@ - if self._check_fields: -@[ if isinstance(member.type, AbstractNestedType) and isinstance(member.type.value_type, BasicType) and member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES]@ -@[ if isinstance(member.type, Array)]@ - if isinstance(value, numpy.ndarray): - assert value.dtype == @(SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['dtype']), \ - "The '@(member.name)' numpy.ndarray() must have the dtype of '@(SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['dtype'])'" - assert value.size == @(member.type.size), \ - "The '@(member.name)' numpy.ndarray() must have a size of @(member.type.size)" - self._@(member.name) = value - return -@[ elif isinstance(member.type, AbstractSequence)]@ - if isinstance(value, array.array): - assert value.typecode == '@(SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['type_code'])', \ - "The '@(member.name)' array.array() must have the type code of '@(SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['type_code'])'" -@[ if isinstance(member.type, BoundedSequence)]@ - assert len(value) <= @(member.type.maximum_size), \ - "The '@(member.name)' array.array() must have a size <= @(member.type.maximum_size)" -@[ end if]@ - self._@(member.name) = value - return -@[ end if]@ -@[ end if]@ -@[ if isinstance(type_, NamespacedType)]@ -@[ if ( - type_.name.endswith(ACTION_GOAL_SUFFIX) or - type_.name.endswith(ACTION_RESULT_SUFFIX) or - type_.name.endswith(ACTION_FEEDBACK_SUFFIX) - )]@ - from @('.'.join(type_.namespaces))._@(convert_camel_case_to_lower_case_underscore(type_.name.rsplit('_', 1)[0])) import @(type_.name) -@[ else]@ - from @('.'.join(type_.namespaces)) import @(type_.name) -@[ end if]@ -@[ end if]@ -@[ if isinstance(member.type, AbstractNestedType)]@ - from collections.abc import Sequence - from collections import UserString -@[ elif isinstance(type_, AbstractGenericString) and type_.has_maximum_size()]@ - from collections import UserString -@[ elif isinstance(type_, BasicType) and type_.typename in CHARACTER_TYPES]@ - from collections import UserString -@[ end if]@ - assert \ -@[ if isinstance(member.type, AbstractNestedType)]@ - ((isinstance(value, Sequence) or - isinstance(value, Set)) and - not isinstance(value, str) and - not isinstance(value, UserString) and -@{assert_msg_suffixes = ['sequence']}@ -@[ if isinstance(type_, AbstractGenericString) and type_.has_maximum_size()]@ - all(len(val) <= @(type_.maximum_size) for val in value) and -@{assert_msg_suffixes.append('and each string value not longer than %d' % type_.maximum_size)}@ -@[ end if]@ -@[ if isinstance(member.type, (Array, BoundedSequence))]@ -@[ if isinstance(member.type, BoundedSequence)]@ - len(value) <= @(member.type.maximum_size) and -@{assert_msg_suffixes.insert(1, 'with length <= %d' % member.type.maximum_size)}@ -@[ else]@ - len(value) == @(member.type.size) and -@{assert_msg_suffixes.insert(1, 'with length %d' % member.type.size)}@ -@[ end if]@ -@[ end if]@ - all(isinstance(v, @(get_python_type(type_))) for v in value) and -@{assert_msg_suffixes.append("and each value of type '%s'" % get_python_type(type_))}@ -@[ if isinstance(type_, BasicType) and type_.typename in SIGNED_INTEGER_TYPES]@ -@{ -nbits = int(type_.typename[3:]) -bound = 2**(nbits - 1) -}@ - all(val >= -@(bound) and val < @(bound) for val in value)), \ -@{assert_msg_suffixes.append('and each integer in [%d, %d]' % (-bound, bound - 1))}@ -@[ elif isinstance(type_, BasicType) and type_.typename in UNSIGNED_INTEGER_TYPES]@ -@{ -nbits = int(type_.typename[4:]) -bound = 2**nbits -}@ - all(val >= 0 and val < @(bound) for val in value)), \ -@{assert_msg_suffixes.append('and each unsigned integer in [0, %d]' % (bound - 1))}@ -@[ elif isinstance(type_, BasicType) and type_.typename == 'char']@ - all(ord(val) >= 0 and ord(val) < 256 for val in value)), \ -@{assert_msg_suffixes.append('and each char in [0, 255]')}@ -@[ elif isinstance(type_, BasicType) and type_.typename in FLOATING_POINT_TYPES]@ -@[ if type_.typename == "float"]@ -@{ -name = "float" -bound = 3.402823466e+38 -}@ - all(not (val < -@(bound) or val > @(bound)) or math.isinf(val) for val in value)), \ -@{assert_msg_suffixes.append('and each float in [%f, %f]' % (-bound, bound))}@ -@[ elif type_.typename == "double"]@ -@{ -name = "double" -bound = 1.7976931348623157e+308 -}@ - all(not (val < -@(bound) or val > @(bound)) or math.isinf(val) for val in value)), \ -@{assert_msg_suffixes.append('and each double in [%f, %f]' % (-bound, bound))}@ -@[ end if]@ -@[ else]@ - True), \ -@[ end if]@ - "The '@(member.name)' field must be @(' '.join(assert_msg_suffixes))" -@[ elif isinstance(member.type, AbstractGenericString) and member.type.has_maximum_size()]@ - (isinstance(value, (str, UserString)) and - len(value) <= @(member.type.maximum_size)), \ - "The '@(member.name)' field must be string value " \ - 'not longer than @(type_.maximum_size)' -@[ elif isinstance(type_, NamespacedType)]@ - isinstance(value, @(type_.name)), \ - "The '@(member.name)' field must be a sub message of type '@(type_.name)'" -@[ elif isinstance(type_, BasicType) and type_.typename == 'octet']@ - (isinstance(value, (bytes, bytearray, memoryview)) and - len(value) == 1), \ - "The '@(member.name)' field must be of type 'bytes' or 'ByteString' with length 1" -@[ elif isinstance(type_, BasicType) and type_.typename == 'char']@ - (isinstance(value, (str, UserString)) and - len(value) == 1 and ord(value) >= -128 and ord(value) < 128), \ - "The '@(member.name)' field must be of type 'str' or 'UserString' " \ - 'with length 1 and the character ord() in [-128, 127]' -@[ elif isinstance(type_, AbstractGenericString)]@ - isinstance(value, str), \ - "The '@(member.name)' field must be of type '@(get_python_type(type_))'" -@[ elif isinstance(type_, BasicType) and type_.typename in (BOOLEAN_TYPE, *FLOATING_POINT_TYPES, *INTEGER_TYPES)]@ - isinstance(value, @(get_python_type(type_))), \ - "The '@(member.name)' field must be of type '@(get_python_type(type_))'" -@[ if type_.typename in SIGNED_INTEGER_TYPES]@ -@{ -nbits = int(type_.typename[3:]) -bound = 2**(nbits - 1) -}@ - assert value >= -@(bound) and value < @(bound), \ - "The '@(member.name)' field must be an integer in [@(-bound), @(bound - 1)]" -@[ elif type_.typename in UNSIGNED_INTEGER_TYPES]@ -@{ -nbits = int(type_.typename[4:]) -bound = 2**nbits -}@ - assert value >= 0 and value < @(bound), \ - "The '@(member.name)' field must be an unsigned integer in [0, @(bound - 1)]" -@[ elif type_.typename in FLOATING_POINT_TYPES]@ -@[ if type_.typename == "float"]@ -@{ -name = "float" -bound = 3.402823466e+38 -}@ -@[ elif type_.typename == "double"]@ -@{ -name = "double" -bound = 1.7976931348623157e+308 -}@ -@[ end if]@ - assert not (value < -@(bound) or value > @(bound)) or math.isinf(value), \ - "The '@(member.name)' field must be a @(name) in [@(-bound), @(bound)]" -@[ end if]@ -@[ else]@ - False -@[ end if]@ +@(generate_check_fields(member)) @[ if isinstance(member.type, AbstractNestedType) and isinstance(member.type.value_type, BasicType) and member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES]@ @[ if isinstance(member.type, Array)]@ self._@(member.name) = numpy.array(value, dtype=@(SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['dtype'])) diff --git a/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py b/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py index c0cf7c9b..a1086e0f 100644 --- a/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py +++ b/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py @@ -29,6 +29,10 @@ from rosidl_parser.definition import ACTION_RESULT_SUFFIX from rosidl_parser.definition import Array from rosidl_parser.definition import BasicType +from rosidl_parser.definition import BOOLEAN_TYPE +from rosidl_parser.definition import BoundedSequence +from rosidl_parser.definition import BoundedString +from rosidl_parser.definition import BoundedWString from rosidl_parser.definition import CHARACTER_TYPES from rosidl_parser.definition import Constant from rosidl_parser.definition import FLOATING_POINT_TYPES @@ -39,6 +43,8 @@ from rosidl_parser.definition import Message from rosidl_parser.definition import NamespacedType from rosidl_parser.definition import Service +from rosidl_parser.definition import SIGNED_INTEGER_TYPES +from rosidl_parser.definition import UNSIGNED_INTEGER_TYPES from rosidl_parser.parser import parse_idl_file from rosidl_pycommon import convert_camel_case_to_lower_case_underscore from rosidl_pycommon import expand_template @@ -452,3 +458,237 @@ def get_setter_and_getter_type(member: Member, type_imports: set[str]) -> tuple[ type_annotations_getter = type_annotations_setter return type_annotations_setter, type_annotations_getter + + +class CodeWriter: + + def __init__(self, start_level: int = 0, indent_size: int = 4): + self._indent = ' ' * indent_size + self._level = start_level + self._lines: list[str] = [] + + def write(self, line: str = '') -> None: + self._lines.append(f'{self._indent * self._level}{line}') + + def indent(self) -> None: + self._level += 1 + + def dedent(self) -> None: + assert self._level > 0 + self._level -= 1 + + def get_value(self) -> str: + return '\n'.join(self._lines) + + +def generate_check_fields(member: Member) -> str: + cw = CodeWriter(start_level=2) + cw.write('if self._check_fields:') + cw.indent() + + type_ = member.type + if isinstance(type_, AbstractNestedType): + type_ = type_.value_type + + if ( + isinstance(member.type, AbstractNestedType) and + isinstance(member.type.value_type, BasicType) and + member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES + ): + if isinstance(member.type, Array): + cw.write('if isinstance(value, numpy.ndarray):') + cw.indent() + + dtype = SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['dtype'] + cw.write(f'assert value.dtype == {dtype}, \\') + cw.indent() + cw.write(f'"The \'{member.name}\' numpy.ndarray() must have the dtype of \'{dtype}\'"') + cw.dedent() + size = member.type.size + cw.write(f'assert value.size == {size}, \\') + cw.indent() + cw.write(f'"The \'{member.name}\' numpy.ndarray() must have a size of {size}"') + cw.dedent() + + elif isinstance(member.type, AbstractSequence): + cw.write('if isinstance(value, array.array):') + cw.indent() + + type_code = SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['type_code'] + cw.write(f"assert value.typecode == '{type_code}', \\") + cw.indent() + cw.write(f'"The \'{member.name}\' array.array() ' + f'must have the type code of \'{type_code}\'"') + cw.dedent() + if isinstance(member.type, BoundedSequence): + max_size = member.type.maximum_size + cw.write(f'assert len(value) <= {max_size}, \\') + cw.indent() + cw.write(f'"The \'{member.name}\' array.array() must have a size <= {max_size}"') + cw.dedent() + + cw.write(f'self._{member.name} = value') + cw.write('return') + cw.dedent() + + if isinstance(type_, NamespacedType): + resolved_namespace = '.'.join(type_.namespaces) + if ( + type_.name.endswith(ACTION_GOAL_SUFFIX) or + type_.name.endswith(ACTION_RESULT_SUFFIX) or + type_.name.endswith(ACTION_FEEDBACK_SUFFIX) + ): + lower_case_action_name = convert_camel_case_to_lower_case_underscore( + type_.name.rsplit('_', 1)[0] + ) + cw.write(f'from {resolved_namespace}._{lower_case_action_name} import {type_.name}') + else: + cw.write(f'from {resolved_namespace} import {type_.name}') + + if isinstance(member.type, AbstractNestedType): + cw.write('from collections.abc import Sequence') + cw.write('from collections import UserString') + elif isinstance(type_, AbstractGenericString) and type_.has_maximum_size(): + cw.write('from collections import UserString') + elif isinstance(type_, BasicType) and type_.typename in CHARACTER_TYPES: + cw.write('from collections import UserString') + + cw.write('assert \\') + cw.indent() + if isinstance(member.type, AbstractNestedType): + cw.write('((isinstance(value, Sequence) or') + cw.write(' isinstance(value, Set)) and') + cw.write(' not isinstance(value, str) and') + cw.write(' not isinstance(value, UserString) and') + + assert_msg_suffixes: list[str] = ['sequence'] + + if isinstance(type_, (BoundedString, BoundedWString)) and type_.has_maximum_size(): + max_size_str = type_.maximum_size + cw.write(f' all(len(val) <= {max_size_str} for val in value) and') + assert_msg_suffixes.append(f'and each string value not longer than {max_size_str}') + + if isinstance(member.type, (Array, BoundedSequence)): + if isinstance(member.type, BoundedSequence): + cw.write(f' len(value) <= {member.type.maximum_size} and') + assert_msg_suffixes.insert(1, f'with length <= {member.type.maximum_size}') + else: + cw.write(f' len(value) == {member.type.size} and') + assert_msg_suffixes.insert(1, f'with length {member.type.size}') + + cw.write(f' all(isinstance(v, {get_python_type(type_)}) for v in value) and') + assert_msg_suffixes.append(f"and each value of type '{get_python_type(type_)}'") + + if ( + isinstance(type_, BasicType) and + type_.typename in (*SIGNED_INTEGER_TYPES, *UNSIGNED_INTEGER_TYPES) + ): + if type_.typename in SIGNED_INTEGER_TYPES: + name = 'integer' + nbits = int(type_.typename[3:]) + bound = 2**(nbits - 1) + lower_bound = -bound + elif type_.typename in UNSIGNED_INTEGER_TYPES: + name = 'unsigned integer' + nbits = int(type_.typename[4:]) + bound = 2**nbits + lower_bound = 0 + + cw.write(f' all(val >= {lower_bound} and val < {bound} for val in value)), \\') + assert_msg_suffixes.append(f'and each {name} in [{lower_bound}, {(bound - 1)}]') + elif isinstance(type_, BasicType) and type_.typename == 'char': + cw.write(' all(ord(val) >= 0 and ord(val) < 256 for val in value)), \\') + assert_msg_suffixes.append('and each char in [0, 255]') + elif isinstance(type_, BasicType) and type_.typename in FLOATING_POINT_TYPES: + if type_.typename == 'float': + name = 'float' + bound_str = '3.402823466e+38' + bound = '{0:.6f}'.format(float(bound_str)) + elif type_.typename == 'double': + name = 'double' + bound_str = '1.7976931348623157e+308' + bound = '{0:.6f}'.format(float(bound_str)) + elif type_.typename == 'long double': + name = 'long double' + bound_str = '1.189731495357231765e+4932' + bound = '{0:.6f}'.format(float(bound_str)) + + isinf_str = 'math.isinf(val) for val in value)' + cw.write(f' all(not (val < -{bound_str} or val > {bound_str}) or {isinf_str}), \\') + assert_msg_suffixes.append(f'and each {name} in [-{bound}, {bound}]') + + else: + cw.write(' True), \\') + + joined_assert_msg_suffixes = ' '.join(assert_msg_suffixes) + cw.write(f'"The \'{member.name}\' field must be {joined_assert_msg_suffixes}"') + + elif ( + isinstance(member.type, (BoundedString, BoundedWString)) and + member.type.has_maximum_size() + ): + cw.write('(isinstance(value, (str, UserString)) and') + cw.write(f' len(value) <= {member.type.maximum_size}), \\') + cw.write(f'"The \'{member.name}\' field must be string value " \\') + assert isinstance(type_, (BoundedString, BoundedWString)) + cw.write(f"'not longer than {type_.maximum_size}'") + elif isinstance(type_, NamespacedType): + cw.write(f'isinstance(value, {type_.name}), \\') + cw.write(f'"The \'{member.name}\' field must be a sub message of type \'{type_.name}\'"') + elif isinstance(type_, BasicType) and type_.typename == 'octet': + cw.write('(isinstance(value, (bytes, bytearray, memoryview)) and') + cw.write(' len(value) == 1), \\') + byte_alias = "'bytes' or 'ByteString'" + cw.write(f'"The \'{member.name}\' field must be of type {byte_alias} with length 1"') + elif isinstance(type_, BasicType) and type_.typename == 'char': + cw.write('(isinstance(value, (str, UserString)) and') + cw.write(' len(value) == 1 and ord(value) >= -128 and ord(value) < 128), \\') + cw.write(f'"The \'{member.name}\' field must be of type \'str\' or \'UserString\' " \\') + cw.write("'with length 1 and the character ord() in [-128, 127]'") + elif isinstance(type_, AbstractGenericString): + cw.write('isinstance(value, str), \\') + cw.write(f'"The \'{member.name}\' field must be of type \'{get_python_type(type_)}\'"') + elif ( + isinstance(type_, BasicType) and + type_.typename in (BOOLEAN_TYPE, *FLOATING_POINT_TYPES, *INTEGER_TYPES) + ): + cw.write(f'isinstance(value, {get_python_type(type_)}), \\') + cw.write(f'"The \'{member.name}\' field must be of type \'{get_python_type(type_)}\'"') + if type_.typename in (*SIGNED_INTEGER_TYPES, *UNSIGNED_INTEGER_TYPES): + if type_.typename in SIGNED_INTEGER_TYPES: + name = 'integer' + nbits = int(type_.typename[3:]) + bound = 2**(nbits - 1) + lower_bound = -bound + elif type_.typename in UNSIGNED_INTEGER_TYPES: + name = 'unsigned integer' + nbits = int(type_.typename[4:]) + bound = 2**nbits + lower_bound = 0 + + cw.dedent() + cw.write(f'assert value >= {lower_bound} and value < {bound}, \\') + cw.indent() + bounds_str = f'[{lower_bound}, {bound - 1}]' + cw.write(f'"The \'{member.name}\' field must be an {name} in {bounds_str}"') + + elif type_.typename in FLOATING_POINT_TYPES: + if type_.typename == 'float': + name = 'float' + bound = 3.402823466e+38 + elif type_.typename == 'double': + name = 'double' + bound = 1.7976931348623157e+308 + elif type_.typename == 'long double': + name = 'long double' + bound = 1.189731495357231765e+4932 + + cw.dedent() + inf_check = ' or math.isinf(value)' + cw.write(f'assert not (value < -{str(bound)} or value > {str(bound)}){inf_check}, \\') + cw.indent() + cw.write(f'"The \'{member.name}\' field must be a {name} in [-{bound}, {bound}]"') + else: + cw.write('False') + + return cw.get_value() From 5bec616abf8f8426810288a6eeba3a528927f840 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Mon, 2 Feb 2026 08:51:10 -0800 Subject: [PATCH 3/6] init Signed-off-by: Michael Carlstrom --- rosidl_generator_py/resource/_msg.py.em | 16 +- .../rosidl_generator_py/generate_py_impl.py | 277 ++++++++++-------- 2 files changed, 163 insertions(+), 130 deletions(-) diff --git a/rosidl_generator_py/resource/_msg.py.em b/rosidl_generator_py/resource/_msg.py.em index e5a86724..a3f44401 100644 --- a/rosidl_generator_py/resource/_msg.py.em +++ b/rosidl_generator_py/resource/_msg.py.em @@ -10,6 +10,11 @@ from rosidl_generator_py.generate_py_impl import get_setter_and_getter_type from rosidl_generator_py.generate_py_impl import SPECIAL_NESTED_BASIC_TYPES from rosidl_generator_py.generate_py_impl import value_to_py from rosidl_generator_py.generate_py_impl import generate_check_fields +from rosidl_generator_py.generate_py_impl import generate_early_return +#def generate_check_fields(a): +# return '' +#def generate_early_return(a): +# return '' from rosidl_parser.definition import AbstractGenericString from rosidl_parser.definition import AbstractNestedType from rosidl_parser.definition import AbstractSequence @@ -505,13 +510,18 @@ if isinstance(member.type, (Array, AbstractSequence)): ' please use a subclass of collections.abc.Sequence like list', DeprecationWarning) @[ end if]@ +@(generate_early_return(member)) @(generate_check_fields(member)) -@[ if isinstance(member.type, AbstractNestedType) and isinstance(member.type.value_type, BasicType) and member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES]@ -@[ if isinstance(member.type, Array)]@ +@[ if isinstance(member.type, AbstractNestedType)]@ +@[ if isinstance(member.type.value_type, BasicType) and member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES]@ +@[ if isinstance(member.type, Array)]@ self._@(member.name) = numpy.array(value, dtype=@(SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['dtype'])) -@[ elif isinstance(member.type, AbstractSequence)]@ +@[ elif isinstance(member.type, AbstractSequence)]@ # type ignore below fixed in mypy 1.17+ see mypy#19421 self._@(member.name) = array.array('@(SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['type_code'])', value) # type: ignore[assignment] +@[ end if]@ +@[ else]@ + self._@(member.name) = list(value) @[ end if]@ @[ else]@ self._@(member.name) = value diff --git a/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py b/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py index a1086e0f..60bd1043 100644 --- a/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py +++ b/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py @@ -406,15 +406,18 @@ def get_setter_and_getter_type(member: Member, type_imports: set[str]) -> tuple[ type_annotations_getter = '' if ( - isinstance(member.type, AbstractNestedType) and isinstance(type_, BasicType) and - type_.typename in SPECIAL_NESTED_BASIC_TYPES + isinstance(member.type, AbstractNestedType) ): - if isinstance(member.type, Array): - type_imports.add('import numpy.typing') - dtype = SPECIAL_NESTED_BASIC_TYPES[type_.typename]['dtype'] - type_annotation = f'numpy.typing.NDArray[{dtype}]' - elif isinstance(member.type, AbstractSequence): - type_annotation = f'array.array[{python_type}]' + if (isinstance(type_, BasicType) and + type_.typename in SPECIAL_NESTED_BASIC_TYPES): + if isinstance(member.type, Array): + type_imports.add('import numpy.typing') + dtype = SPECIAL_NESTED_BASIC_TYPES[type_.typename]['dtype'] + type_annotation = f'numpy.typing.NDArray[{dtype}]' + elif isinstance(member.type, AbstractSequence): + type_annotation = f'array.array[{python_type}]' + else: + type_annotation = f'list[{python_type}]' # Using Annotated because of mypy#3004 type_annotations_getter = f'typing.Annotated[typing.Any, {type_annotation}]' @@ -422,7 +425,11 @@ def get_setter_and_getter_type(member: Member, type_imports: set[str]) -> tuple[ if isinstance(member.type, AbstractNestedType): sequence_type = f'collections.abc.Sequence[{python_type}]' - if type_annotation != '': + if ( + isinstance(type_, BasicType) and + type_.typename in SPECIAL_NESTED_BASIC_TYPES and + isinstance(member.type, Array) + ): type_annotation = f'typing.Union[{type_annotation}, {sequence_type}]' else: type_annotation = sequence_type @@ -481,149 +488,165 @@ def get_value(self) -> str: return '\n'.join(self._lines) -def generate_check_fields(member: Member) -> str: +def generate_imports(member: Member) -> None: cw = CodeWriter(start_level=2) - cw.write('if self._check_fields:') - cw.indent() + +def _sequence_check_fields(member: AbstractNestedType, cw: CodeWriter) -> None: type_ = member.type if isinstance(type_, AbstractNestedType): type_ = type_.value_type + cw.write('assert \\') + cw.indent() + cw.write('((isinstance(value, Sequence) or') + cw.write(' isinstance(value, Set)) and') + cw.write(' not isinstance(value, str) and') + cw.write(' not isinstance(value, UserString) and') + + assert_msg_suffixes: list[str] = ['sequence'] + + if isinstance(type_, (BoundedString, BoundedWString)) and type_.has_maximum_size(): + max_size_str = type_.maximum_size + cw.write(f' all(len(val) <= {max_size_str} for val in value) and') + assert_msg_suffixes.append(f'and each string value not longer than {max_size_str}') + + if isinstance(member.type, (Array, BoundedSequence)): + if isinstance(member.type, BoundedSequence): + cw.write(f' len(value) <= {member.type.maximum_size} and') + assert_msg_suffixes.insert(1, f'with length <= {member.type.maximum_size}') + else: + cw.write(f' len(value) == {member.type.size} and') + assert_msg_suffixes.insert(1, f'with length {member.type.size}') + + cw.write(f' all(isinstance(v, {get_python_type(type_)}) for v in value) and') + assert_msg_suffixes.append(f"and each value of type '{get_python_type(type_)}'") + if ( - isinstance(member.type, AbstractNestedType) and - isinstance(member.type.value_type, BasicType) and - member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES + isinstance(type_, BasicType) and + type_.typename in (*SIGNED_INTEGER_TYPES, *UNSIGNED_INTEGER_TYPES) ): - if isinstance(member.type, Array): - cw.write('if isinstance(value, numpy.ndarray):') - cw.indent() + if type_.typename in SIGNED_INTEGER_TYPES: + name = 'integer' + nbits = int(type_.typename[3:]) + bound = 2**(nbits - 1) + lower_bound = -bound + elif type_.typename in UNSIGNED_INTEGER_TYPES: + name = 'unsigned integer' + nbits = int(type_.typename[4:]) + bound = 2**nbits + lower_bound = 0 + + cw.write(f' all(val >= {lower_bound} and val < {bound} for val in value)), \\') + assert_msg_suffixes.append(f'and each {name} in [{lower_bound}, {(bound - 1)}]') + elif isinstance(type_, BasicType) and type_.typename == 'char': + cw.write(' all(ord(val) >= 0 and ord(val) < 256 for val in value)), \\') + assert_msg_suffixes.append('and each char in [0, 255]') + elif isinstance(type_, BasicType) and type_.typename in FLOATING_POINT_TYPES: + if type_.typename == 'float': + name = 'float' + bound_str = '3.402823466e+38' + bound = '{0:.6f}'.format(float(bound_str)) + elif type_.typename == 'double': + name = 'double' + bound_str = '1.7976931348623157e+308' + bound = '{0:.6f}'.format(float(bound_str)) + elif type_.typename == 'long double': + name = 'long double' + bound_str = '1.189731495357231765e+4932' + bound = '{0:.6f}'.format(float(bound_str)) + + isinf_str = 'math.isinf(val) for val in value)' + cw.write(f' all(not (val < -{bound_str} or val > {bound_str}) or {isinf_str}), \\') + assert_msg_suffixes.append(f'and each {name} in [-{bound}, {bound}]') - dtype = SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['dtype'] - cw.write(f'assert value.dtype == {dtype}, \\') - cw.indent() - cw.write(f'"The \'{member.name}\' numpy.ndarray() must have the dtype of \'{dtype}\'"') - cw.dedent() - size = member.type.size - cw.write(f'assert value.size == {size}, \\') - cw.indent() - cw.write(f'"The \'{member.name}\' numpy.ndarray() must have a size of {size}"') - cw.dedent() + else: + cw.write(' True), \\') - elif isinstance(member.type, AbstractSequence): - cw.write('if isinstance(value, array.array):') - cw.indent() + joined_assert_msg_suffixes = ' '.join(assert_msg_suffixes) + cw.write(f'"The \'{member.name}\' field must be {joined_assert_msg_suffixes}"') - type_code = SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['type_code'] - cw.write(f"assert value.typecode == '{type_code}', \\") - cw.indent() - cw.write(f'"The \'{member.name}\' array.array() ' - f'must have the type code of \'{type_code}\'"') - cw.dedent() - if isinstance(member.type, BoundedSequence): - max_size = member.type.maximum_size - cw.write(f'assert len(value) <= {max_size}, \\') + +def generate_early_return(member: Member) -> str: + cw = CodeWriter(start_level=2) + + type_ = member.type + if isinstance(type_, AbstractNestedType): + type_ = type_.value_type + else: + return '' + + if isinstance(member.type, AbstractNestedType): + if ( + isinstance(member.type.value_type, BasicType) and + member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES + ): + if isinstance(member.type, Array): + cw.write('if isinstance(value, numpy.ndarray):') cw.indent() - cw.write(f'"The \'{member.name}\' array.array() must have a size <= {max_size}"') + cw.write('if self._check_fields:') + cw.indent() + dtype = SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['dtype'] + cw.write(f'assert value.dtype == {dtype}, \\') + cw.indent() + cw.write(f'"The \'{member.name}\' numpy.ndarray() must have the dtype of \'{dtype}\'"') + cw.dedent() + size = member.type.size + cw.write(f'assert value.size == {size}, \\') + cw.indent() + cw.write(f'"The \'{member.name}\' numpy.ndarray() must have a size of {size}"') + cw.dedent() + elif isinstance(member.type, AbstractSequence): + cw.write('if isinstance(value, array.array):') + cw.indent() + cw.write('if self._check_fields:') + cw.indent() + type_code = SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['type_code'] + cw.write(f"assert value.typecode == '{type_code}', \\") + cw.indent() + cw.write(f'"The \'{member.name}\' array.array() ' + f'must have the type code of \'{type_code}\'"') cw.dedent() + if isinstance(member.type, BoundedSequence): + max_size = member.type.maximum_size + cw.write(f'assert len(value) <= {max_size}, \\') + cw.indent() + cw.write(f'"The \'{member.name}\' array.array() must have a size <= {max_size}"') + cw.dedent() + else: + cw.write('if isinstance(value, list):') + cw.indent() + cw.write('if self._check_fields:') + cw.indent() + _sequence_check_fields(member, cw) + cw.dedent() + + cw.dedent() cw.write(f'self._{member.name} = value') cw.write('return') cw.dedent() - if isinstance(type_, NamespacedType): - resolved_namespace = '.'.join(type_.namespaces) - if ( - type_.name.endswith(ACTION_GOAL_SUFFIX) or - type_.name.endswith(ACTION_RESULT_SUFFIX) or - type_.name.endswith(ACTION_FEEDBACK_SUFFIX) - ): - lower_case_action_name = convert_camel_case_to_lower_case_underscore( - type_.name.rsplit('_', 1)[0] - ) - cw.write(f'from {resolved_namespace}._{lower_case_action_name} import {type_.name}') - else: - cw.write(f'from {resolved_namespace} import {type_.name}') + return cw.get_value() - if isinstance(member.type, AbstractNestedType): - cw.write('from collections.abc import Sequence') - cw.write('from collections import UserString') - elif isinstance(type_, AbstractGenericString) and type_.has_maximum_size(): - cw.write('from collections import UserString') - elif isinstance(type_, BasicType) and type_.typename in CHARACTER_TYPES: - cw.write('from collections import UserString') - cw.write('assert \\') +def generate_check_fields(member: Member) -> str: + cw = CodeWriter(start_level=2) + cw.write('if self._check_fields:') cw.indent() - if isinstance(member.type, AbstractNestedType): - cw.write('((isinstance(value, Sequence) or') - cw.write(' isinstance(value, Set)) and') - cw.write(' not isinstance(value, str) and') - cw.write(' not isinstance(value, UserString) and') - - assert_msg_suffixes: list[str] = ['sequence'] - - if isinstance(type_, (BoundedString, BoundedWString)) and type_.has_maximum_size(): - max_size_str = type_.maximum_size - cw.write(f' all(len(val) <= {max_size_str} for val in value) and') - assert_msg_suffixes.append(f'and each string value not longer than {max_size_str}') - - if isinstance(member.type, (Array, BoundedSequence)): - if isinstance(member.type, BoundedSequence): - cw.write(f' len(value) <= {member.type.maximum_size} and') - assert_msg_suffixes.insert(1, f'with length <= {member.type.maximum_size}') - else: - cw.write(f' len(value) == {member.type.size} and') - assert_msg_suffixes.insert(1, f'with length {member.type.size}') - - cw.write(f' all(isinstance(v, {get_python_type(type_)}) for v in value) and') - assert_msg_suffixes.append(f"and each value of type '{get_python_type(type_)}'") - - if ( - isinstance(type_, BasicType) and - type_.typename in (*SIGNED_INTEGER_TYPES, *UNSIGNED_INTEGER_TYPES) - ): - if type_.typename in SIGNED_INTEGER_TYPES: - name = 'integer' - nbits = int(type_.typename[3:]) - bound = 2**(nbits - 1) - lower_bound = -bound - elif type_.typename in UNSIGNED_INTEGER_TYPES: - name = 'unsigned integer' - nbits = int(type_.typename[4:]) - bound = 2**nbits - lower_bound = 0 - - cw.write(f' all(val >= {lower_bound} and val < {bound} for val in value)), \\') - assert_msg_suffixes.append(f'and each {name} in [{lower_bound}, {(bound - 1)}]') - elif isinstance(type_, BasicType) and type_.typename == 'char': - cw.write(' all(ord(val) >= 0 and ord(val) < 256 for val in value)), \\') - assert_msg_suffixes.append('and each char in [0, 255]') - elif isinstance(type_, BasicType) and type_.typename in FLOATING_POINT_TYPES: - if type_.typename == 'float': - name = 'float' - bound_str = '3.402823466e+38' - bound = '{0:.6f}'.format(float(bound_str)) - elif type_.typename == 'double': - name = 'double' - bound_str = '1.7976931348623157e+308' - bound = '{0:.6f}'.format(float(bound_str)) - elif type_.typename == 'long double': - name = 'long double' - bound_str = '1.189731495357231765e+4932' - bound = '{0:.6f}'.format(float(bound_str)) - isinf_str = 'math.isinf(val) for val in value)' - cw.write(f' all(not (val < -{bound_str} or val > {bound_str}) or {isinf_str}), \\') - assert_msg_suffixes.append(f'and each {name} in [-{bound}, {bound}]') + type_ = member.type + if isinstance(type_, AbstractNestedType): + type_ = type_.value_type - else: - cw.write(' True), \\') + if isinstance(member.type, AbstractNestedType): + _sequence_check_fields(member, cw) + return cw.get_value() - joined_assert_msg_suffixes = ' '.join(assert_msg_suffixes) - cw.write(f'"The \'{member.name}\' field must be {joined_assert_msg_suffixes}"') + cw.write('assert \\') + cw.indent() - elif ( + if ( isinstance(member.type, (BoundedString, BoundedWString)) and member.type.has_maximum_size() ): From 8bfe5052ada3177636e2353c407522f12267f469 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Mon, 2 Feb 2026 09:45:57 -0800 Subject: [PATCH 4/6] implementation complete Signed-off-by: Michael Carlstrom --- rosidl_generator_py/resource/_msg.py.em | 17 ++--- .../rosidl_generator_py/generate_py_impl.py | 74 ++++++++++++------- 2 files changed, 54 insertions(+), 37 deletions(-) diff --git a/rosidl_generator_py/resource/_msg.py.em b/rosidl_generator_py/resource/_msg.py.em index a3f44401..9dbd05d4 100644 --- a/rosidl_generator_py/resource/_msg.py.em +++ b/rosidl_generator_py/resource/_msg.py.em @@ -1,6 +1,5 @@ @# Included from rosidl_generator_py/resource/_idl.py.em @{ - from rosidl_pycommon import convert_camel_case_to_lower_case_underscore from rosidl_generator_py.generate_py_impl import constant_value_to_py from rosidl_generator_py.generate_py_impl import get_python_type @@ -9,12 +8,9 @@ from rosidl_generator_py.generate_py_impl import get_type_annotation_default from rosidl_generator_py.generate_py_impl import get_setter_and_getter_type from rosidl_generator_py.generate_py_impl import SPECIAL_NESTED_BASIC_TYPES from rosidl_generator_py.generate_py_impl import value_to_py -from rosidl_generator_py.generate_py_impl import generate_check_fields -from rosidl_generator_py.generate_py_impl import generate_early_return -#def generate_check_fields(a): -# return '' -#def generate_early_return(a): -# return '' +from rosidl_generator_py.generate_py_impl import generate_guards +# def generate_guards(a): +# return ''= from rosidl_parser.definition import AbstractGenericString from rosidl_parser.definition import AbstractNestedType from rosidl_parser.definition import AbstractSequence @@ -500,18 +496,15 @@ if isinstance(member.type, (Array, AbstractSequence)): @@@(member.name).setter@(noqa_string) def @(member.name)(self, value: @(type_annotations_setter[member.name])) -> None:@(noqa_string) - @[ if isinstance(member.type, AbstractNestedType)]@ - from collections.abc import Set - if isinstance(value, Set): + if isinstance(value, collections.abc.Set): import warnings warnings.warn( 'Using set or subclass of set is deprecated,' ' please use a subclass of collections.abc.Sequence like list', DeprecationWarning) @[ end if]@ -@(generate_early_return(member)) -@(generate_check_fields(member)) +@(generate_guards(member)) @[ if isinstance(member.type, AbstractNestedType)]@ @[ if isinstance(member.type.value_type, BasicType) and member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES]@ @[ if isinstance(member.type, Array)]@ diff --git a/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py b/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py index 60bd1043..b11c7d16 100644 --- a/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py +++ b/rosidl_generator_py/rosidl_generator_py/generate_py_impl.py @@ -408,8 +408,10 @@ def get_setter_and_getter_type(member: Member, type_imports: set[str]) -> tuple[ if ( isinstance(member.type, AbstractNestedType) ): - if (isinstance(type_, BasicType) and - type_.typename in SPECIAL_NESTED_BASIC_TYPES): + if ( + isinstance(type_, BasicType) and + type_.typename in SPECIAL_NESTED_BASIC_TYPES + ): if isinstance(member.type, Array): type_imports.add('import numpy.typing') dtype = SPECIAL_NESTED_BASIC_TYPES[type_.typename]['dtype'] @@ -488,21 +490,19 @@ def get_value(self) -> str: return '\n'.join(self._lines) -def generate_imports(member: Member) -> None: - cw = CodeWriter(start_level=2) - - -def _sequence_check_fields(member: AbstractNestedType, cw: CodeWriter) -> None: +def _sequence_check_fields(member: Member, cw: CodeWriter) -> None: type_ = member.type if isinstance(type_, AbstractNestedType): type_ = type_.value_type + else: + return cw.write('assert \\') cw.indent() - cw.write('((isinstance(value, Sequence) or') - cw.write(' isinstance(value, Set)) and') + cw.write('((isinstance(value, collections.abc.Sequence) or') + cw.write(' isinstance(value, collections.abc.Set)) and') cw.write(' not isinstance(value, str) and') - cw.write(' not isinstance(value, UserString) and') + cw.write(' not isinstance(value, collections.UserString) and') assert_msg_suffixes: list[str] = ['sequence'] @@ -567,14 +567,32 @@ def _sequence_check_fields(member: AbstractNestedType, cw: CodeWriter) -> None: cw.write(f'"The \'{member.name}\' field must be {joined_assert_msg_suffixes}"') -def generate_early_return(member: Member) -> str: - cw = CodeWriter(start_level=2) +def generate_imports(member: Member, cw: CodeWriter) -> None: + type_ = member.type + if isinstance(type_, AbstractNestedType): + type_ = type_.value_type + if isinstance(type_, NamespacedType): + resolved_namespace = '.'.join(type_.namespaces) + if ( + type_.name.endswith(ACTION_GOAL_SUFFIX) or + type_.name.endswith(ACTION_RESULT_SUFFIX) or + type_.name.endswith(ACTION_FEEDBACK_SUFFIX) + ): + lower_case_action_name = convert_camel_case_to_lower_case_underscore( + type_.name.rsplit('_', 1)[0] + ) + cw.write(f'from {resolved_namespace}._{lower_case_action_name} import {type_.name}') + else: + cw.write(f'from {resolved_namespace} import {type_.name}') + + +def generate_early_return(member: Member, cw: CodeWriter) -> None: type_ = member.type if isinstance(type_, AbstractNestedType): type_ = type_.value_type else: - return '' + return if isinstance(member.type, AbstractNestedType): if ( @@ -582,6 +600,7 @@ def generate_early_return(member: Member) -> str: member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES ): if isinstance(member.type, Array): + comment_front = f"The '{member.name}' numpy.ndarray() must have" cw.write('if isinstance(value, numpy.ndarray):') cw.indent() cw.write('if self._check_fields:') @@ -589,29 +608,31 @@ def generate_early_return(member: Member) -> str: dtype = SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['dtype'] cw.write(f'assert value.dtype == {dtype}, \\') cw.indent() - cw.write(f'"The \'{member.name}\' numpy.ndarray() must have the dtype of \'{dtype}\'"') + cw.write(f'"{comment_front} the dtype of \'{dtype}\'"') cw.dedent() size = member.type.size cw.write(f'assert value.size == {size}, \\') cw.indent() - cw.write(f'"The \'{member.name}\' numpy.ndarray() must have a size of {size}"') + cw.write(f'"{comment_front} have a size of {size}"') cw.dedent() elif isinstance(member.type, AbstractSequence): cw.write('if isinstance(value, array.array):') cw.indent() cw.write('if self._check_fields:') cw.indent() - type_code = SPECIAL_NESTED_BASIC_TYPES[member.type.value_type.typename]['type_code'] + type_code = SPECIAL_NESTED_BASIC_TYPES[ + member.type.value_type.typename]['type_code'] cw.write(f"assert value.typecode == '{type_code}', \\") cw.indent() cw.write(f'"The \'{member.name}\' array.array() ' - f'must have the type code of \'{type_code}\'"') + f'must have the type code of \'{type_code}\'"') cw.dedent() if isinstance(member.type, BoundedSequence): max_size = member.type.maximum_size cw.write(f'assert len(value) <= {max_size}, \\') cw.indent() - cw.write(f'"The \'{member.name}\' array.array() must have a size <= {max_size}"') + cw.write(f'"The \'{member.name}\' array.array() ' + f'must have a size <= {max_size}"') cw.dedent() else: @@ -627,11 +648,8 @@ def generate_early_return(member: Member) -> str: cw.write('return') cw.dedent() - return cw.get_value() - -def generate_check_fields(member: Member) -> str: - cw = CodeWriter(start_level=2) +def generate_check_fields(member: Member, cw: CodeWriter) -> None: cw.write('if self._check_fields:') cw.indent() @@ -641,7 +659,7 @@ def generate_check_fields(member: Member) -> str: if isinstance(member.type, AbstractNestedType): _sequence_check_fields(member, cw) - return cw.get_value() + return cw.write('assert \\') cw.indent() @@ -650,7 +668,7 @@ def generate_check_fields(member: Member) -> str: isinstance(member.type, (BoundedString, BoundedWString)) and member.type.has_maximum_size() ): - cw.write('(isinstance(value, (str, UserString)) and') + cw.write('(isinstance(value, (str, collections.UserString)) and') cw.write(f' len(value) <= {member.type.maximum_size}), \\') cw.write(f'"The \'{member.name}\' field must be string value " \\') assert isinstance(type_, (BoundedString, BoundedWString)) @@ -664,7 +682,7 @@ def generate_check_fields(member: Member) -> str: byte_alias = "'bytes' or 'ByteString'" cw.write(f'"The \'{member.name}\' field must be of type {byte_alias} with length 1"') elif isinstance(type_, BasicType) and type_.typename == 'char': - cw.write('(isinstance(value, (str, UserString)) and') + cw.write('(isinstance(value, (str, collections.UserString)) and') cw.write(' len(value) == 1 and ord(value) >= -128 and ord(value) < 128), \\') cw.write(f'"The \'{member.name}\' field must be of type \'str\' or \'UserString\' " \\') cw.write("'with length 1 and the character ord() in [-128, 127]'") @@ -714,4 +732,10 @@ def generate_check_fields(member: Member) -> str: else: cw.write('False') + +def generate_guards(member: Member) -> str: + cw = CodeWriter(start_level=2) + generate_imports(member, cw) + generate_early_return(member, cw) + generate_check_fields(member, cw) return cw.get_value() From cdf1071fc95d2c46b4aa3a8b7adfbe4f81415234 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Mon, 2 Feb 2026 16:39:35 -0800 Subject: [PATCH 5/6] add tests for castig Signed-off-by: Michael Carlstrom --- rosidl_generator_py/test/test_interfaces.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rosidl_generator_py/test/test_interfaces.py b/rosidl_generator_py/test/test_interfaces.py index 8d11d423..64225d9c 100644 --- a/rosidl_generator_py/test/test_interfaces.py +++ b/rosidl_generator_py/test/test_interfaces.py @@ -532,6 +532,10 @@ def test_arrays() -> None: with pytest.warns(DeprecationWarning): Arrays(string_values={'bar', 'baz', 'foo'}) + msg.bool_values = (False, False, False) + assert isinstance(msg.bool_values, list) + assert msg.bool_values == [False, False, False] + def test_bounded_sequences() -> None: msg = BoundedSequences(check_fields=True) @@ -756,6 +760,10 @@ def test_bounded_sequences() -> None: float64_ieee_max_next = numpy.nextafter(1.7976931348623157e+308, math.inf) setattr(msg, 'float64_values', [-float64_ieee_max_next, 0.0, float64_ieee_max_next]) + msg.bool_values = (True, False) + assert isinstance(msg.bool_values, list) + assert msg.bool_values == [True, False] + def test_unbounded_sequences() -> None: msg = UnboundedSequences(check_fields=True) @@ -905,6 +913,10 @@ def test_unbounded_sequences() -> None: float64_ieee_max_next = numpy.nextafter(1.7976931348623157e+308, math.inf) setattr(msg, 'float64_values', [-float64_ieee_max_next, 0.0, float64_ieee_max_next]) + msg.bool_values = (True, False, True, False) + assert isinstance(msg.bool_values, list) + assert msg.bool_values == [True, False, True, False] + def test_slot_attributes() -> None: msg = Nested(check_fields=True) From c8d855d6f98a8715bb857fe965f5e37fa2d764d7 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Mon, 2 Feb 2026 16:59:26 -0800 Subject: [PATCH 6/6] remove comment Signed-off-by: Michael Carlstrom --- rosidl_generator_py/resource/_msg.py.em | 2 -- 1 file changed, 2 deletions(-) diff --git a/rosidl_generator_py/resource/_msg.py.em b/rosidl_generator_py/resource/_msg.py.em index 9dbd05d4..e80f5b17 100644 --- a/rosidl_generator_py/resource/_msg.py.em +++ b/rosidl_generator_py/resource/_msg.py.em @@ -9,8 +9,6 @@ from rosidl_generator_py.generate_py_impl import get_setter_and_getter_type from rosidl_generator_py.generate_py_impl import SPECIAL_NESTED_BASIC_TYPES from rosidl_generator_py.generate_py_impl import value_to_py from rosidl_generator_py.generate_py_impl import generate_guards -# def generate_guards(a): -# return ''= from rosidl_parser.definition import AbstractGenericString from rosidl_parser.definition import AbstractNestedType from rosidl_parser.definition import AbstractSequence