[Python-Dev] Problems with unicode_literals (original) (raw)
Barry Warsaw barry at python.org
Sat Jan 17 23:58:59 CET 2009
- Previous message: [Python-Dev] Problems with unicode_literals
- Next message: [Python-Dev] Problems with unicode_literals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Jan 16, 2009, at 10:52 PM, Benjamin Peterson wrote:
On Fri, Jan 16, 2009 at 9:45 PM, Barry Warsaw <barry at python.org> wrote:
The optparse one could easily be fixed for 2.6, if we agree it should be fixed. This untested patch should do it I think: Index: Lib/optparse.py =================================================================== - --- Lib/optparse.py (revision 68465) +++ Lib/optparse.py (working copy) @@ -994,7 +994,7 @@ """addoption(Option) addoption(optstr, ..., kwarg=val, ...) """ - - if type(args[0]) is types.StringType: + if type(args[0]) in types.StringTypes: option = self.optionclass(*args, **kwargs) elif len(args) == 1 and not kwargs: option = args[0] It'd probably be better to replace that whole line with isinstance(args[0], basestring).
I thought about that, but clearly the style of that module is to use
the 'is' test. I'm assuming that's because of some required backward
compatibility reason, but honestly I didn't check, I just copied the
style of the file.
The fact that 'a' and 'b' are unicodes and not accepted as keyword arguments is probably the tougher problem. I haven't yet looked at what it might take to fix. Is it worth fixing in 2.6 or is this a wait-for-2.7 thing? Actually, this looks like a one line fix, too: --- Python/ceval.c (revision 68625) +++ Python/ceval.c (working copy) @@ -2932,7 +2932,8 @@ PyObject keyword = kws[2i]; PyObject value = kws[2i + 1]; int j; - if (keyword == NULL || ! PyStringCheck(keyword)) { + if (keyword == NULL || ! (PyStringCheck(keyword) || + PyUnicodeCheck(keyword))) { PyErrFormat(PyExcTypeError, "%.200s() keywords must be strings", PyStringAsString(co->coname));
That seems reasonable.
But I agree with Guido when he says this should be a 2.7 feature.
As does that.
- -Barry
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Darwin)
iQCVAwUBSXJis3EjvBPtnXfVAQLnsAP+I7ZIa8vKwSJV+cGqlFyKYNdyYysxYW5w QL36DMXMwfg+Gddb5GN16IGXZt54yTneFAp6fxNgq55Seql/LFmhSrYoq0dk0uXz +sb92PRtYD7QjV6BkOUFlIGphmuOS7Vxv6+M2Xi1YoSyU6DHhno0AyYUFa3ysJiC lfNP6TLgGL0= =mp9M -----END PGP SIGNATURE-----
- Previous message: [Python-Dev] Problems with unicode_literals
- Next message: [Python-Dev] Problems with unicode_literals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]