Re:Dictionary union (PEP 584) is merged
by dahfizz on Tuesday February 25, 2020 @11:13PM
(#22420211)
This seems pretty straightforward. When doing
`dict(d1, d2)`
You are calling the dict function, and using the normal syntax for unpacking a dictionary into kwargs. In this case, the name for kwargs must be strings.
Re:Dictionary union (PEP 584) is merged
by uryga on Wednesday February 26, 2020 @07:19AM
(#22422301)
yeah, that side of the (in)equation was pretty obvious, i was mostly interested in the `{...}` one. i admit that a bytecode listing probably isn't the best exposition, i just like digging into VM stuff :)
---
i was curious why the two double-stars behave differently despite syntactic similarity. so i went and checked the bytecode, and it turns out they compile down to different opcodes! `{××d1, ××d2}` yields a BUILD_MAP_UNPACK, while `dict(d1, ××d2)` yields a CALL_FUNCTION_EX/CALL_FUNCTION_KW (depending on the CPython version)