On Tue, Mar 5, 2019 at 2:38 AM Inada Naoki <songofacandy@gmail.com> wrote:
On Tue, Mar 5, 2019 at 7:26 PM Steven D'Aprano <steve@pearwood.info> wrote:
On Sat, Mar 02, 2019 at 01:47:37AM +0900, INADA Naoki wrote:
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].
I don't think so. https://bugs.python.org/issue35105 and https://mail.python.org/pipermail/python-dev/2018-October/155435.html are about kwargs. I think non string keys are allowed for {**d1, **d2} by language.
Is this documented somewhere?
It is not explicitly documented. But unlike keyword argument, dict display supported non-string keys from very old.
I believe {3: 4} is supported by Python language, not CPython implementation behavior.
https://docs.python.org/3/reference/expressions.html#grammar-token-dict-disp...
I'd like to remove all doubt: {**d1} needs to work regardless of the key type, as long as it's hashable (d1 could be some mapping implemented without hashing, e.g. using a balanced tree, so that it could support unhashable keys). If there's doubt about this anywhere, we could add an example to the docs and to the PEP. -- --Guido van Rossum (python.org/~guido)