[issue39694] Incorrect dictionary unpacking when calling str.format

Ammar Askar report at bugs.python.org
Thu Feb 20 05:48:15 EST 2020


Ammar Askar <ammar at ammaraskar.com> added the comment:

Can re-create, this is because the **kwargs handling inside unicode format only performs a lookup when needed https://github.com/python/cpython/blob/c4cacc8c5eab50db8da3140353596f38a01115ca/Objects/stringlib/unicode_format.h#L393-L424 and doesn't eagerly check it like here https://github.com/python/cpython/blob/ffd9753a944916ced659b2c77aebe66a6c9fbab5/Objects/call.c#L985-L1010

This might not be worth fixing though because of the very common pattern of 

  "{abcd}".format(**locals())

This would take a pretty dramatic performance hit for a relatively uncommon edge case.

----------
nosy: +ammar2, eric.smith, serhiy.storchaka, vstinner

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39694>
_______________________________________


More information about the Python-bugs-list mailing list