New submission from Jason R. Coombs:
Today I encountered a bug where I was using a Distutils.Command subclass, which
uses getopt for option parsing. The implementation is here:
https://bitbucket.org/jaraco/jaraco.packaging/src/2.2/jaraco/packaging/depends.py?at=default
Around line 59, the options are defined, but because the syntax is Python 3
style with unicode literals, under Python 2.7, those get created as unicode
objects.
When I invoke that Command under Python 2.7, I get this error:
Traceback (most recent call last):
File "setup.py", line 160, in <module>
setup(**setup_params)
File "/usr/lib/python2.7/distutils/core.py", line 138, in setup
ok = dist.parse_command_line()
File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 250, in
parse_command_line
File "/usr/lib/python2.7/distutils/dist.py", line 467, in parse_command_line
args = self._parse_command_opts(parser, args)
File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 533, in
_parse_command_opts
File "/usr/lib/python2.7/distutils/dist.py", line 564, in _parse_command_opts
(args, opts) = parser.getopt(args[1:])
File "/usr/lib/python2.7/distutils/fancy_getopt.py", line 253, in getopt
self._grok_option_table()
File "/usr/lib/python2.7/distutils/fancy_getopt.py", line 171, in
_grok_option_table
"must be a string of length >= 2") % long
distutils.errors.DistutilsGetoptError: invalid long option 'requirement=': must
be a string of length >= 2
That error is raised because 'requirement=' is a Unicode, but the test in
fancy_getopt is isinstance(opt, str).
I can work around the issue by wrapping all of the options in str() calls,
which leaves them unchanged on Python 3 and downcasts them to strings on Python
2, but that's not pretty.
I suggest that fancy_getopt should either include 'unicode' in the isinstance
test or (if unicode values really aren't supported), encode unicode values
first.
----------
components: Library (Lib)
messages: 197020
nosy: jason.coombs
priority: low
severity: normal
status: open
title: getopt chokes on unicode option names
versions: Python 2.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue18936>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com