[New-bugs-announce] [issue39694] Incorrect dictionary unpacking when calling str.format
Akos Kiss
report at bugs.python.org
Thu Feb 20 05:03:23 EST 2020
New submission from Akos Kiss <akosthekiss at gmail.com>:
My understanding was that in function calls, the keys in an **expression had to be strings. However, str.format seems to deviate from that and allows non-string keys in the mapping (and silently ignores them).
Please, see the transcript below:
>>> def f(): pass
...
>>> def g(): pass
...
>>> x = {None: ''}
>>> y = {1: ''}
>>> f(**x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() keywords must be strings
>>> f(**y)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() keywords must be strings
>>> g(**x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: g() keywords must be strings
>>> g(**y)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: g() keywords must be strings
>>> ''.format(**x)
''
>>> ''.format(**y)
''
I could reproduce this (incorrect?) behavior on macOS with python 3.4-3.7 and on Ubuntu 18.04 with python 3.6.
----------
messages: 362304
nosy: Akos Kiss
priority: normal
severity: normal
status: open
title: Incorrect dictionary unpacking when calling str.format
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39694>
_______________________________________
More information about the New-bugs-announce
mailing list