Issue2646
Created on 2008-04-16 21:40 by j5, last changed 2022-04-11 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| allow_unicode_keywords.patch | j5, 2008-04-16 21:40 | |||
| issue2646.diff | belopolsky, 2008-04-17 05:26 | Patch against revision 62359 | ||
| Messages (4) | |||
|---|---|---|---|
| msg65567 - (view) | Author: John (J5) Palmieri (j5) | Date: 2008-04-16 21:40 | |
# given this function
def a(**kwargs):
pass
# this works
a(**{'b':'c'})
# this throws a format error
a(**{u'b':'c'})
I am using a web framework (TurboGears w/ genshi templating) which often
pass around dictionaries as keyword arguments in order to have 1 to 1
representation of json data and URL parameters. This is usually fine
except when using libraries such as simplejson which encodes all of the
keywords as unicode.
Attached is a patch which is most likely just the tip of the iceberg but
hopefully it turns out to be this easy.
|
|||
| msg65568 - (view) | Author: John (J5) Palmieri (j5) | Date: 2008-04-16 22:15 | |
Someone has convinced me that it is not worth bothering the dev team since they will have this fixed in P3k the right way. If it is easy then please fix this, otherwise feel free to close. |
|||
| msg65572 - (view) | Author: Alexander Belopolsky (belopolsky) * ![]() |
Date: 2008-04-17 04:43 | |
I would say this is a good idea for 2.6.
Note that C functions are more forgiving:
>>> from datetime import *
>>> date(1,2,**{u'day':10})
datetime.date(1, 2, 10)
>>> dict(**{u'x':1,2:3,():5})
{u'x': 1, 2: 3, (): 5}
but
>>> date(1,2,**{u'day':10,u'x':20})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: keywords must be strings
I would not advocate making ** completely promiscuous (as in dict(..)
above), but permitting unicode strings will allow for easier 3.0
transitions.
I'll submit a patch.
|
|||
| msg86639 - (view) | Author: Daniel Diniz (ajaksu2) * ![]() |
Date: 2009-04-27 01:23 | |
Fixed in r68805, #4978. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:33 | admin | set | github: 46898 |
| 2009-04-27 01:23:28 | ajaksu2 | set | status: open -> closed superseder: allow unicode keyword args nosy:
+ ajaksu2 |
| 2008-05-13 08:33:57 | georg.brandl | set | priority: normal keywords: + 26backport, - patch |
| 2008-04-17 06:13:33 | loewis | set | versions: + Python 2.6, - Python 2.5 |
| 2008-04-17 05:26:24 | belopolsky | set | files: + issue2646.diff |
| 2008-04-17 04:43:49 | belopolsky | set | nosy:
+ belopolsky messages: + msg65572 |
| 2008-04-16 22:15:48 | j5 | set | messages: + msg65568 |
| 2008-04-16 21:40:05 | j5 | create | |

