-
Notifications
You must be signed in to change notification settings - Fork 76
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
Conversation
openfisca_core/parameters.py
Outdated
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🙂.
👏 |
Once this is merged, we will also need to automatically publish python 3 versions of our packages on pypi.