{**d1, **d2} vs dict(**d1, **d2) #10058
-
Is this intended behaviour: # MicroPython v1.19.1-469-g8a1c9464e on 2022-10-04; Raspberry Pi Pico W with RP2040
d1 = {'a': 1}
d2 = {'b': 2}
# This works:
dict(**d1, **d2)
# >>> {'a': 1, 'b': 2}
# This fails:
{**d1, **d2}
# >>> SyntaxError: invalid syntax No problem at all to use the constructor - but just curious about the latter. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
In my Python 3.10.8 console |
Beta Was this translation helpful? Give feedback.
-
This is a slightly controversial feature, to the extent that they "replaced" it with the | operator -- i.e. |
Beta Was this translation helpful? Give feedback.
-
#5807 seems to indicate that PEP584 has only been implemented for function args. |
Beta Was this translation helpful? Give feedback.
-
FYI: PEP 584 is now supported #8523 |
Beta Was this translation helpful? Give feedback.
{**d1, **d2}
is a Python 3.5 feature, described in PEP 448. MicroPython is Python 3.4 with a selection of features from later versions (including some features from that same PEP).This is a slightly controversial feature, to the extent that they "replaced" it with the | operator -- i.e.
d1 | d2
-- described in PEP 584 (which was added in Python 3.9)