[Python-Dev] Problems with unicode_literals

Barry Warsaw barry at python.org
Sat Jan 17 03:42:34 CET 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've been playing with 'from __future__ import unicode_literals' just  
to see how unicode unclean some of my code was.  Almost everything was  
fairly easy to fix but I found two interesting situations.  One seems  
fairly shallow and might arguably be fixable in Python 2.6 (but  
probably not :).  The other clearly can't be addressed in Python 2.6,  
but the question is whether it should be changed for Python 2.7.

Here's some sample code:

- -----snip snip-----
from __future__ import unicode_literals

def foo(a=None, b=None):
     print a, b

# This is a TypeError
foo(**{'a': 1, 'b': 2})

foo(**dict(a=1, b=2))

from optparse import OptionParser

parser = OptionParser()

# This also raises a TypeError
parser.add_option('-f', '--foo')
- -----snip snip-----

The add_option() failure is a one-line fix.

- -Barry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iQCVAwUBSXFFmnEjvBPtnXfVAQKx0QP/Un7RG++ugtgywBHXd+pWTD2V7QC1JDqP
rpIkwqocicMZiNBbg0NS5/TSGHa0CyaQphDmBBeNFr7jFb4rxdUESyLmBNNIz7dV
/PEBZxJp5ZjTGCIylEJoXHMSN102wqe/n6QAAGqV5ce7e3Fhr8b7kU2m7cMT6yDQ
/1b4riH/H0Y=
=dp0u
-----END PGP SIGNATURE-----


More information about the Python-Dev mailing list