Skip to content

Commit

Permalink
Fix type annotation of array types in constructor (#17)
Browse files Browse the repository at this point in the history
The type annotation of keyword arguments in the constructor of a message
used the `getter` property. While this is fine for simple types, for
array types it breaks down as:
- `getter` always returns an array
- `setter` takes any sequence as input
So we should be using the setter type.

How to reproduce:
1. Create a message containing an array type such as the following
   `Vector.msg`:
   ```
   float64[] data
   ```
2. Type-check the following snippet:
   ```python
   from my_pkg.msg import Vector
   vec = Vector(data=[1, 2, 3])
   ```

Without this commit:
```
Argument "data" to "Vector" has incompatible type "List[float]"; expected "array[float]"  [arg-type]
```

With this commit: no errors
  • Loading branch information
haudren-woven authored Sep 28, 2023
1 parent 996e3c4 commit bc572c1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion resource/_msg.pyi.em
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class @(message.structure.namespaced_type.name)(metaclass=Metaclass_@(message.st
*,
@[end if]@
@[for name, annotation, noqa_string in members]@
@(name): @(annotation.getter) = ...,@(noqa_string)
@(name): @(annotation.setter) = ...,@(noqa_string)
@[end for]@
**kwargs: typing.Any,
) -> None: ...
Expand Down

0 comments on commit bc572c1

Please sign in to comment.