mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #26489: Add dictionary unpacking support to Tools/parser/unparse.py
Patch by Guo Ci Teo.
This commit is contained in:
parent
e88dd1c32c
commit
d66dd5ce68
3 changed files with 20 additions and 3 deletions
|
@ -393,12 +393,21 @@ class Unparser:
|
|||
|
||||
def _Dict(self, t):
|
||||
self.write("{")
|
||||
def write_pair(pair):
|
||||
(k, v) = pair
|
||||
def write_key_value_pair(k, v):
|
||||
self.dispatch(k)
|
||||
self.write(": ")
|
||||
self.dispatch(v)
|
||||
interleave(lambda: self.write(", "), write_pair, zip(t.keys, t.values))
|
||||
|
||||
def write_item(item):
|
||||
k, v = item
|
||||
if k is None:
|
||||
# for dictionary unpacking operator in dicts {**{'y': 2}}
|
||||
# see PEP 448 for details
|
||||
self.write("**")
|
||||
self.dispatch(v)
|
||||
else:
|
||||
write_key_value_pair(k, v)
|
||||
interleave(lambda: self.write(", "), write_item, zip(t.keys, t.values))
|
||||
self.write("}")
|
||||
|
||||
def _Tuple(self, t):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue