[issue9161] add_option in optparse no longer accepts unicode string

Craig McQueen report at bugs.python.org
Mon Jul 5 07:36:32 CEST 2010


New submission from Craig McQueen <python at craig.mcqueen.id.au>:

Working in Japan, I find it very helpful to be able to read full Unicode arguments in Python 2.x under Windows 2000/XP. So I am using the following:

http://stackoverflow.com/questions/846850/how-to-read-unicode-characters-from-command-line-arguments-in-python-on-windows/846931#846931

Brilliantly, the optparse module in Python 2.6 has worked fine with Unicode arguments. Sadly, it seems Python 2.7 is preventing this. When I try to run my program with Python 2.7, I get the following:

  ...
  File "c:\python27\lib\optparse.py", line 1018, in add_option
    raise TypeError, "invalid arguments"
TypeError: invalid arguments

It seems that the type check in optparse.py line 1018 has changed from this in 2.6:
    if type(args[0]) in types.StringTypes:

to this in 2.7:
    if type(args[0]) is types.StringType:

This makes it more difficult to support Unicode in 2.7, compared to 2.6. Any chance this could be reverted?

----------
messages: 109300
nosy: cmcqueen1975
priority: normal
severity: normal
status: open
title: add_option in optparse no longer accepts unicode string
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9161>
_______________________________________


More information about the Python-bugs-list mailing list