-
Notifications
You must be signed in to change notification settings - Fork 64
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 py3 bytes #85
Fix py3 bytes #85
Conversation
fixing inefficient canon method in rostime (ros#77)
This allows sending |
047039c
to
2ac4b03
Compare
@dirk-thomas any input/advice there ? It seems to me that we're stuck in a corner without any perfect solution (since going either the full unicode string way would change too much, and enforcing only ascii string might break existing code). From what I understand the existing code in This fix at least fix the breaking case when a user attempts to send It would be good if there were tests actually ensuring the serialization and deserialization function are inverse of one another (for the proper types, in any language version), I couldn't find any here. |
The user is supposed to pass a
This is exactly why the wiki page says that unicode is not supported. The API / mapping only works correctly for ASCII across languages / versions (Python 2 vs. Python 3 vs. C++). This is a really difficult topic - especially with the different languages needing to inter-operate well. Even in ROS 2 support for unicode hasn't been completed (even though we have the "freedom" to break behavior there (if necessary) and don't have to support Python 2). So from my point of view it is yet unclear how to change the spec (and after that the implementation) to satisfy all the goals and constraints. |
Yes this is a difficult topic with all language needed to interoperate. And
python2 and python3 have different types for this, so they could even be
considered different languages.
And we can keep the spec the same, but a "specification" should be
abstracted from any possible implementation, therefore not related to any
language construct (including C)
My perspective on this is "a library should not impose different semantics
on the user/dev than the semantics of the language it is interfacing with".
Otherwise you get into horror stories of people writing crazy code that
might eventually have to be maintained forever...
So, since unicode is not supported, lets forget about it for now.
1) As far as I understand the current ros field string spec is: "ascii
string". This should be implemented in python3 with bytes. So the rospy
library should not expose str for an ascii string in the python3 case,
because we need to match the language semantics. In python2, the library
should expose str and not unicode.
"The user is supposed to pass a str in python3" -> this is an
implementation error in my view.
This is what I am focusing on here, to make what should work, sending bytes
, work.
The second step would be to expose bytes on the other end, but not sure
if/how we ll break things, so that can be another PR...
At this step I would consider the utf8 part of the implementation
incomplete, since only one encoding is supported, and confusing, since we
have one implementation for two different languages py2 and py3 for the
same ros type supporting two usecases (ascii or unicode).
Ideally I would remove it but we cant break things that already "work" for
users we cannot control. So :
2) How an ascii string is different from a uint8[] ? Do we need an extra
ros unistring field type ? How do we serialize the encoding ? These would
be the questions that need to be answered in order to cover unicode strings
in the message field specification.
|
Imo Python 3 code should be allows to assign
I would argue that an
Since the current "string" type is only defined for ASCII I would argue yes, we need another type like "wstring".
The encoding can either be agreed on in the spec (e.g. UTF-8) or could be stored beside the payload in a separate "field".
Additionally the exact mapping to language specific types need to be defined as well as the behavior of that API (e.g. what happens if the user passes a different type? Is there some conversion happening or not?). This is exactly what we are trying to answer / decide for ROS 2 (which still doesn't support beyond ASCII atm). Please see ros2/design#117 and ros2/design#130. |
This is however unspecified behavior, since
The only point of this PR.
My point of view here is :
If the array serialization algorithm encode the size of the array, then the Anyway I ll join the design conversation, but it shouldn't be in the way of this PR as far as I can see... |
I was mostly referring to the use case that the caller should be able to pass a Python 3 |
See ros#85 for more discussion
That constraint however is not matching the laguage semantics, therefore
not checkable by the language tools (even later when we add python3 types)
which means it should be checked by the ros library, but that is not
implemented (and it should be clearly documented that it is not the primary
specified behavior nor a stable reliable implementation to avoid confusion
like the one we are having now, where I expect ASCII string to translate to
bytes in py3 - both ways - and have bytes py3 type tested and always
working, but the unicode unspecified solution is the half implemented py3
behavior ).
I would agree however with the naive expectation that a ros string should
accept *any* unicode utf8 string, but this still needs to be specified, and
it will change/break quite a few things in a few places like python did
between 2 and 3... so it s maybe not for ROS1 ?
Following for ROS1 it means that :
- the unspecified behavior (accepting unicode) should be completely dropped
(and translate to bytes for py3 instead of str should be implemented), OR
- that constraint of limiting to ASCII characters and accepting unicode
string (but translate to bytes for py3) should be implemented in the
library, OR
- we eventually will follow ROS2 and break existing user code starting from
a specific distro, doing whatever ROS2 decides to do. I commented on the
linked design discussions about that.
Nothing ideal here, and code migration pain is lurking around the corner in
any case...
|
I will close this for now due to the age / inactivity and because the upcoming ROS Noetic being the first ROS distro officially targeting Python 3. If the problem still exists in Noetic please open a new ticket with steps to reproduce. |
I fixed this while working on another package and testing message serialization for python3.
It works fine for me, but I am not sure what kind of test can be added for this here...