Author xtreak
Recipients Marcus.Smith, Suzumizaki, dstufft, ncoghlan, paul.moore, tanbro-liu, xtreak
Date 2018-09-23.05:48:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1537681705.25.0.956365154283.issue24307@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks for the patch. Would you like to make a GitHub PR. I think it's a problem with optparse in general while trying to have a default value with unicode character and %default in the help string. The same code is present in Python 3 but strings are unicode by default. An example code will be below : 

# -*- coding: utf-8 -*-

from optparse import OptionParser

parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
                  help="write to FILE. Default value %default", metavar="FILE", default="早上好")

(options, args) = parser.parse_args()

$ python3.6 ../backups/bpo24307.py --help
Usage: bpo24307.py [options]

Options:
  -h, --help            show this help message and exit
  -f FILE, --file=FILE  write to FILE. Default value 早上好

$ python2.7 ../backups/bpo24307.py --help
Traceback (most recent call last):
  File "../backups/bpo24307.py", line 9, in <module>
    (options, args) = parser.parse_args()
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1400, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1440, in _process_args
    self._process_long_opt(rargs, values)
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1515, in _process_long_opt
    option.process(opt, value, values, self)
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 789, in process
    self.action, self.dest, opt, value, values, parser)
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 811, in take_action
    parser.print_help()
  File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1670, in print_help
    file.write(self.format_help().encode(encoding, "replace"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 148: ordinal not in range(128)


Thanks
History
Date User Action Args
2018-09-23 05:48:25xtreaksetrecipients: + xtreak, paul.moore, ncoghlan, Suzumizaki, dstufft, Marcus.Smith, tanbro-liu
2018-09-23 05:48:25xtreaksetmessageid: <1537681705.25.0.956365154283.issue24307@psf.upfronthosting.co.za>
2018-09-23 05:48:25xtreaklinkissue24307 messages
2018-09-23 05:48:24xtreakcreate