Message358305
Another obvious way to do it, but I'm +1 on it.
A small side point however - PEP 584 reads:
> To create a new dict containing the merged items of two (or more) dicts, one can currently write:
> {**d1, **d2}
> but this is neither obvious nor easily discoverable. It is only guaranteed to work if the keys are all strings. If the keys are not strings, it currently works in CPython, but it may not work with other implementations, or future versions of CPython[2].
...
> [2] Non-string keys: https://bugs.python.org/issue35105 and https://mail.python.org/pipermail/python-dev/2018-October/155435.html
The references cited does not back this assertion up. Perhaps the intent is to reference the "cool/weird hack" dict(d1, **d2) (see https://mail.python.org/pipermail/python-dev/2010-April/099485.html and https://mail.python.org/pipermail/python-dev/2010-April/099459.html), which allowed any hashable keys in Python 2 but only strings in Python 3.
If I see {**d1, **d2}, my expectations are that this is the new generalized unpacking and I currently expect any keys to be allowed, and the PEP should be updated to accurately reflect this to prevent future misunderstandings. |
|
Date |
User |
Action |
Args |
2019-12-12 21:16:45 | Aaron Hall | set | recipients:
+ Aaron Hall, gvanrossum, rhettinger, mark.dickinson, scoder, serhiy.storchaka, josh.r, slam, xtreak, brandtbucher |
2019-12-12 21:16:45 | Aaron Hall | set | messageid: <1576185405.71.0.338354888482.issue36144@roundup.psfhosted.org> |
2019-12-12 21:16:45 | Aaron Hall | link | issue36144 messages |
2019-12-12 21:16:45 | Aaron Hall | create | |
|