Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bytes for uint8[] field #40

Merged
merged 2 commits into from
May 9, 2021
Merged
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
5 changes: 5 additions & 0 deletions genmypy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def _get_genmsg_type(first_party_package, field_type, imports):
base_field_type, is_array, array_len = genmsg.msgs.parse_type(field_type)
assert is_array
# TODO: Handle array_len (use typing.Annotated?)

if base_field_type == "uint8":
# Special case for uint8[]
return "bytes"

base_type = _get_genmsg_type(first_party_package, base_field_type, imports)
return "typing.List[{}]".format(base_type)

Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/expected/sensor_msgs/msg/_Image.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Image(genpy.Message):
encoding: str
is_bigendian: int
step: int
data: typing.List[int]
data: bytes

def __init__(
self,
Expand All @@ -29,7 +29,7 @@ class Image(genpy.Message):
encoding: str = ...,
is_bigendian: int = ...,
step: int = ...,
data: typing.List[int] = ...,
data: bytes = ...,
*args: typing.Any,
**kwds: typing.Any,
) -> None: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PointCloud2(genpy.Message):
is_bigendian: bool
point_step: int
row_step: int
data: typing.List[int]
data: bytes
is_dense: bool

def __init__(
Expand All @@ -33,7 +33,7 @@ class PointCloud2(genpy.Message):
is_bigendian: bool = ...,
point_step: int = ...,
row_step: int = ...,
data: typing.List[int] = ...,
data: bytes = ...,
is_dense: bool = ...,
*args: typing.Any,
**kwds: typing.Any,
Expand Down