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

Make package compatible with Python 3 #660

Merged
merged 15 commits into from
May 14, 2018
Merged

Make package compatible with Python 3 #660

merged 15 commits into from
May 14, 2018

Conversation

fpagnoux
Copy link
Member

@fpagnoux fpagnoux commented May 12, 2018

Once this is merged, we will also need to automatically publish python 3 versions of our packages on pypi.

@fpagnoux fpagnoux requested review from Anna-Livia and sandcha May 12, 2018 22:30
return "ParameterAtInstant({})".format({self.instant_str: self.value}).encode('utf-8')
result = "ParameterAtInstant({})".format({self.instant_str: self.value})
# repr output must be encoded in Python 2, but not in Python 3
if sys.version_info < (3, 0):
Copy link
Contributor

@Anna-Livia Anna-Livia May 14, 2018

Choose a reason for hiding this comment

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

Could this be a to_utf8 function ?It seem to happen several times in the code

Copy link
Member Author

Choose a reason for hiding this comment

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

In both Python 2 and 3, __repr__ must return a str. But str has a different meaning in Python 2 and 3 😒: it is a byte in Python 2, but a unicode in Python 3.

We only want to encode the string in UTF-8 in Python 2, as in Python 3 we want to return a unicode. So if if we extracted the function, that would be to_utf8_if_python2, which doesn't seem great.

If all this encoding business is not clear for you, as it was for me a few days ago, I'd recommend this article[FR]. I can't pretend I understand everything now, but it's more clear 🙂.

@fpagnoux fpagnoux merged commit 3d5084a into master May 14, 2018
@fpagnoux fpagnoux deleted the python3 branch May 14, 2018 21:28
@bonjourmauko
Copy link
Member

👏

@bonjourmauko bonjourmauko added the kind:feat A feature request, a feature deprecation label Jul 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:feat A feature request, a feature deprecation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants