Skip to content

Commit

Permalink
Fix non printable ASCII characters getting recognised as stringlike (#…
Browse files Browse the repository at this point in the history
…246)

This workaround will be rendered unnecessary once OpenCyphal/specification#51 is implemented.
  • Loading branch information
silverv authored Sep 9, 2022
1 parent 243c776 commit 42d948e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pycyphal/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.10.1"
__version__ = "1.10.2"
6 changes: 4 additions & 2 deletions pycyphal/dsdl/_builtin_form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2019 OpenCyphal
# This software is distributed under the terms of the MIT License.
# Author: Pavel Kirienko <pavel@opencyphal.org>

import string
import typing
import logging
import numpy
Expand Down Expand Up @@ -60,7 +60,9 @@ def _to_builtin_impl(

if isinstance(model, pydsdl.ArrayType):
assert isinstance(obj, numpy.ndarray)
if model.string_like: # TODO: drop this special case when strings are natively supported in DSDL.
# TODO: drop this special case when strings are natively supported in DSDL.
printable = set(map(ord, string.printable))
if model.string_like and all(map(lambda x: x in printable, obj.tobytes())):
try:
return bytes(e for e in obj).decode()
except UnicodeError:
Expand Down
2 changes: 1 addition & 1 deletion tests/dsdl/_builtin_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _unittest_slow_builtin_form_manual(compiled: typing.List[pycyphal.dsdl.Gener
"name": "org.node.my",
"software_image_crc": [0x0DDDEADB16B00B5],
# The following will have to be changed when strings are supported natively in DSDL:
"certificate_of_authenticity": bytes(range(100)).decode(),
"certificate_of_authenticity": list(range(100)),
}

bi = pycyphal.dsdl.to_builtin(
Expand Down

0 comments on commit 42d948e

Please sign in to comment.