Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions rosidl_generator_py/resource/_msg.py.em
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,29 @@ if isinstance(member.type, (Array, AbstractSequence)):

@[ if isinstance(member.type, AbstractNestedType)]@
from collections.abc import Set
from collections.abc import Sequence
from collections.abc import MutableSequence
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',
' please use a subclass of collections.abc.MutableSequence like list',
DeprecationWarning)
@[ if isinstance(member.type, Array) and isinstance(member.type.value_type, BasicType) and member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES]@
if isinstance(value, Sequence) and not isinstance(value, (MutableSequence, numpy.ndarray)):
import warnings
warnings.warn(
"Using a subclass of Sequence that isn't a subclass of MutableSequence is deprecated,"
' please use a subclass of collections.abc.MutableSequence like list or a numpy.ndarray',
DeprecationWarning)
@[ else]@
if isinstance(value, Sequence) and not isinstance(value, MutableSequence):
import warnings
warnings.warn(
"Using a subclass of Sequence that isn't a subclass of MutableSequence is deprecated,"
' please use a subclass of collections.abc.MutableSequence like list',
DeprecationWarning)
@[ end if]@
@[ 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]@
Expand Down Expand Up @@ -538,7 +555,6 @@ if isinstance(member.type, (Array, AbstractSequence)):
@[ 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
Expand Down
6 changes: 6 additions & 0 deletions rosidl_generator_py/test/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ def test_arrays() -> None:
with pytest.warns(DeprecationWarning):
Arrays(string_values={'bar', 'baz', 'foo'})

with pytest.warns(DeprecationWarning):
Arrays(string_values=('bar', 'baz', 'foo'))

msg4 = Arrays(int8_values=numpy.array([4, 5, 3], dtype=numpy.int8))
assert msg3 == msg4


def test_bounded_sequences() -> None:
msg = BoundedSequences(check_fields=True)
Expand Down