Skip to content

Commit

Permalink
Fix the annotation for non trivial sequence (#20)
Browse files Browse the repository at this point in the history
Before this PR, unbounded sequences of non trivial types (e.g.
`std_msgs/Header[]`) would be annotated as `Sequence[T]` which is not
mutable.

This would make type-checking fail on code generating such a msg, e.g.

```python

def make_header() -> std_msgs.msg.Header: ...

my_msg = Mymsg()
for i in range(10):
    my_msg.data.append(make_header())
```

This fails because there's no `append` method on `Sequence`.

By making the type annotation `MutableSequence` the problem goes away.
  • Loading branch information
gergondet-woven authored Jun 16, 2024
1 parent bc572c1 commit df4bb1a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion rosidl_generator_mypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def to_type_annotation(

# eg: std_msgs/Header[]
return Annotation(
"typing.Sequence[{}]".format(type_annotation.getter),
"typing.MutableSequence[{}]".format(type_annotation.getter),
"typing.Sequence[{}]".format(type_annotation.setter),
)

Expand Down

0 comments on commit df4bb1a

Please sign in to comment.