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

Fix non printable ASCII characters getting recognised as stringlike #246

Merged
merged 2 commits into from
Sep 9, 2022
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
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