[2.7] bpo-24307: Fix unicode error in optparse with unicode value for %default#9911
[2.7] bpo-24307: Fix unicode error in optparse with unicode value for %default#9911tirkarthi wants to merge 3 commits intopython:2.7from
Conversation
|
Seems, there is some encoding difference while testing this on Windows. Unfortunately, I don't have a Windows machine to debug this :( |
|
I found one more error where if the conflicting option is a unicode string then it throws |
|
Sorry, I had to close and reopen twice. First Appveyor hanged and Travis failed so I closed and reopened while Appveyor was hanging. So Appveyor marked it as cancelled and didn't run while Travis ran. When Travis completed I closed and reopened PR but it seems Appveyor marked it as cancelled forever and closing and opening doesn't help. Thus it shows build failure. If someone has privilege to re-run the build then it will be helpful since I don't want to close and reopen again to waste CI resources. Thanks |
vstinner
left a comment
There was a problem hiding this comment.
I see a high risk of breaking applications which currently work as expected. If the default value is a non-ASCII string, unicode() will raise a UnicodeDecodeError.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I'm not sure that I understood the change, so I remove my vote.
|
Closing the PR as per https://bugs.python.org/issue24307#msg332337 |
optparseallows%defaultin the help string where a default value can be supplied. '%default' is replaced with the given value. If the given value is a unicode value than it fails withUnicodeEncodeErrorin Python 2.7. This is not a problem in Python 3 since all strings are unicode by default. This patch encodes the value before replacement and adds tests.It's based on the patch by tanbro-liu in the bug tracker. Since there was no response from tanbro-liu I have converted the patch as a PR with test and attribution to tanbro-liu.
https://bugs.python.org/issue24307