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 bug __repr__ting an XmlModel on Python3 (doesn't define unicode) #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jgomo3
Copy link

@jgomo3 jgomo3 commented Feb 4, 2017

Note: This is a proposal. We could discuss this and if you will, you could help me to test better this change.

The __repr__ implementation on class XmlModel uses the function
unicode which is only defined in Python 2. So in Python 3, this
raises an exception.

I changed the usage of unicode with smart_str from
django.utils.encoding as it promises to use smart_bytes if
running in Python 2 and smart_text if Python 3.

What happens is that Python 3 expects __repr__ to return a
str not a bytestring. That's why changed the import logic and
leverage on Django logic behind the smart_* methods handling
Python 2 and 3.

The `__repr__` implementation on class `XmlModel` uses the function
`unicode` which is only defined in Python 2. So in Python 3, this
raises an exception.

I changed the usage of `unicode` with `smart_str` from
`django.utils.encoding` as it promises to use `smart_bytes` if
running in Python 2 and `smart_text` if Python 3.

What happens is that Python 3 expects `__repr__` to return a
`str` not a bytestring. That's why changed the import logic and
leverage on Django logic behind the `smart_*` methods handling
Python 2 and 3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant