Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use dict with unicode keys as keyword arguments #44926

Closed
complex mannequin opened this issue May 3, 2007 · 5 comments
Closed

Cannot use dict with unicode keys as keyword arguments #44926

complex mannequin opened this issue May 3, 2007 · 5 comments
Labels
topic-unicode type-feature A feature request or enhancement

Comments

@complex
Copy link
Mannequin

complex mannequin commented May 3, 2007

BPO 1712419
Nosy @malemburg, @birkenfeld, @rhettinger

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2007-05-19.18:14:27.000>
created_at = <Date 2007-05-03.22:49:23.000>
labels = ['type-feature', 'expert-unicode']
title = 'Cannot use dict with unicode keys as keyword arguments'
updated_at = <Date 2007-05-19.18:14:27.000>
user = 'https://bugs.python.org/complex'

bugs.python.org fields:

activity = <Date 2007-05-19.18:14:27.000>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Unicode']
creation = <Date 2007-05-03.22:49:23.000>
creator = 'complex'
dependencies = []
files = []
hgrepos = []
issue_num = 1712419
keywords = []
message_count = 5.0
messages = ['55096', '55097', '55098', '55099', '55100']
nosy_count = 4.0
nosy_names = ['lemburg', 'georg.brandl', 'rhettinger', 'complex']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue1712419'
versions = []

@complex
Copy link
Mannequin Author

complex mannequin commented May 3, 2007

Unicode strings cannot be used as keys in dictionaries passed as keyword argument to a function. For example:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def fn(**kw):
...     print repr(kw)
...
>>> fn(**{u'x':1})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: fn() keywords must be strings
>>>

Unicode strings should be converted to str automatically using the site specific default encoding or something similar solution.

This bug caused problems when decoding dictionaries from data formats such as XML or JSON. Usually unicode strings are returned from such modules, such as simplejson. Manual encoding from unicode to str causes performance loss if this cannot be done by Python automatically.

@complex complex mannequin closed this as completed May 3, 2007
@complex complex mannequin added topic-unicode type-feature A feature request or enhancement labels May 3, 2007
@complex complex mannequin closed this as completed May 3, 2007
@complex complex mannequin added topic-unicode type-feature A feature request or enhancement labels May 3, 2007
@birkenfeld
Copy link
Member

In any case, this is a feature request.

@malemburg
Copy link
Member

Python (currently) does not allow non-ASCII identifiers, so it's not surprising that Unicode parameter names don't work.

It's also a really bad idea to pass data from an AJAX XML or JSON request directly to a function without doing at least some post-processing of the data in order to prevent DOS attacks, code injection, etc.

dict((str(key), value) for key, value in kw.iteritems()) is all that's needed for the above.

BTW, I don't think those few micro-seconds really matter in the face of XML or JSON decoding, network latency, etc. ;-)

@rhettinger
Copy link
Contributor

Recommend closing this as not-a-bug.

@birkenfeld
Copy link
Member

Yeah, should be uncontroversial.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-unicode type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants