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

Preserve Unicode strings when passed to utility functions #377

Merged
merged 1 commit into from
Dec 31, 2018

Conversation

svisser
Copy link
Collaborator

@svisser svisser commented Dec 28, 2018

First of all, best wishes for 2019.

This updates the string utility functions to return a Unicode string when a Unicode string is passed in. In Python 2 this would raise an error due to the use of str(v).

This is a change related to issue #374.

The tests also check for other types (int) to preserve existing functionality.

@svisser svisser self-assigned this Dec 28, 2018
@svisser svisser requested a review from alecthomas December 28, 2018 15:51
@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 95.43% when pulling c8be8f1 on svisser:fix/issue_374 into c2e1cfd on alecthomas:master.

@coveralls
Copy link

coveralls commented Dec 28, 2018

Coverage Status

Coverage increased (+0.02%) to 95.387% when pulling 2f8412a on svisser:fix/issue_374 into 9644956 on alecthomas:master.

@@ -14,7 +16,11 @@ def Lower(v):
>>> s('HI')
'hi'
"""
return str(v).lower()
if _PY2 and isinstance(v, unicode):
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe replace this repeated fragment with a mini helper function? _fix_str(v) or something?

@alecthomas
Copy link
Owner

One minor comment but overall LGTM 👍

@alecthomas
Copy link
Owner

Also, happy New Year!

This updates the string utility functions to return a Unicode
string when a Unicode string is passed in. In Python 2 this would
raise an error due to the use of str(v).

This is a change related to issue alecthomas#374.

The tests also check for other types (int) to preserve existing
functionality.
@svisser
Copy link
Collaborator Author

svisser commented Dec 31, 2018

That's fair, I have updated the commit - with the Python 2 check inlined as we hopefully won't need it anymore when Python 2 reaches end of life at the end of next year ;)

@alecthomas alecthomas merged commit 7e18e1c into alecthomas:master Dec 31, 2018
@svisser svisser deleted the fix/issue_374 branch December 31, 2018 13:21
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.

3 participants