summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-03-06 14:50:15 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-03-06 14:50:15 (GMT)
commitd66dd5ce68cbf4a33c385439d5eeb2bff4e860f1 (patch)
tree2a110e9d32aa7ad9aa1b0e44845628c526d11925 /Tools
parente88dd1c32c2961e0fe40b09c48904451fa1eba9a (diff)
downloadcpython-d66dd5ce68cbf4a33c385439d5eeb2bff4e860f1.zip
cpython-d66dd5ce68cbf4a33c385439d5eeb2bff4e860f1.tar.gz
cpython-d66dd5ce68cbf4a33c385439d5eeb2bff4e860f1.tar.bz2
Issue #26489: Add dictionary unpacking support to Tools/parser/unparse.py
Patch by Guo Ci Teo.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/parser/unparse.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py
index c828577..285030e 100644
--- a/Tools/parser/unparse.py
+++ b/Tools/parser/unparse.py
@@ -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):