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

tools: Let unicode error messages through #6154

Merged
merged 1 commit into from
Feb 22, 2018
Merged

Conversation

geky
Copy link
Contributor

@geky geky commented Feb 21, 2018

Some toolchains (GCC) may emit error messages with unicode symbols based on the your localization settings. Instead of being passed to the user as is, the unicode causes an exception.

I'm not sure exactly what the correct fix is regarding python2+3 compat, but changing str to unicode seems to work on my setup (x86_64-linux-gnu-gcc 5.4.0 + python 2.7.12 + mbed-os-5c7cd1f + LANG=en_US.UTF-8)

cc @theotherjimmy

Copy link
Contributor

@theotherjimmy theotherjimmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unicode does not exist in Python 3. Please import it from six or do a try: ... except ImportError: like utils.py

@geky
Copy link
Contributor Author

geky commented Feb 21, 2018

Ah, it looks like from builtins import str gets you a unicode compatible str function. @theotherjimmy does this work for you?

@theotherjimmy
Copy link
Contributor

theotherjimmy commented Feb 21, 2018

@geky Nope. That returns a str on both python 2 and 3. str is bytes for 2 and unicode for 3. They are not compatible. Turns out that the Python documentation indicates that this is the same as str and IS WRONG.

@geky
Copy link
Contributor Author

geky commented Feb 21, 2018

It seems to behave as unicode, even in python2:

$ python2 -c 'from builtins import str; print(str(u"\U0001f60b"))'
$ python3 -c 'from builtins import str; print(str(u"\U0001f60b"))'

This module contains backports the data types that were significantly changed in the transition from Python 2 to Python 3. [Including] an implementation of Python 3’s str object (pure Python subclass of Python 2’s builtin unicode type)

http://python-future.org/reference.html#module-future.builtins

@theotherjimmy
Copy link
Contributor

@geky That website is quite confusing: it seems to indicate that it's describing the python-future package. Are they talking about a competitor to six? or is this builtin?

@theotherjimmy
Copy link
Contributor

Either way, Sure you can use that import. It seems to work. Just take a look at the rest of the file to verify that you're not breaking any other str invocations (I don't think that will)

Some toolchains (GCC) may emit error messages with unicode symbols based on
the your localization settings. Instead of being passed to the user as is,
the unicode causes an exception.
@geky
Copy link
Contributor Author

geky commented Feb 21, 2018

I don't know why it is and it is confusing, but the builtins module (not __builtins__) seems to have all of the python3 builtins for python2.

I tested most of the other str invocations they all should probably have been unicode strings anyways.

Copy link
Contributor

@theotherjimmy theotherjimmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@theotherjimmy
Copy link
Contributor

/morph build

@mbed-ci
Copy link

mbed-ci commented Feb 21, 2018

Build : SUCCESS

Build number : 1207
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6154/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Feb 21, 2018

@mbed-ci
Copy link

mbed-ci commented Feb 21, 2018

@cmonr cmonr merged commit 6c4654a into master Feb 22, 2018
@adbridge
Copy link
Contributor

Also reliant on #5848 for 5.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants