New submission from Cyphase:

Python 2.7.6: Affected
Python 3.2.3: Not affected

dict() allows keyword expansion using a dict() with integer keys, whereas 
attempting to do so with most other functions raises a TypeError with the 
message, "keywords must be strings". The same thing happens with 
collections.defaultdict(), but not collections.Counter() or 
collections.OrderedDict, presumably because they override dict.__init__().

>>> old_dict = {'a': 1, 2: 'b'}
>>> old_dict
{'a': 1, 2: 'b'}
>>> other_dict = {'c': 3, 4: 'd'}
>>> other_dict
>>> new_dict = dict(old_dict, **other_dict)
>>> new_dict
{'a': 1, 2: 'b', 4: 'd', 'c': 3}

I feel like this must be known, but I didn't find anything with a search.

----------
components: Interpreter Core
messages: 216938
nosy: Cyphase
priority: normal
severity: normal
status: open
title: dict() allows keyword expansion with integer keys, e.g. dict(**{5:'v'})
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21320>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to