summaryrefslogtreecommitdiffstats
path: root/Tools/parser
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-03-06 14:50:44 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-03-06 14:50:44 (GMT)
commitd07a1cb53b3d5b3b68b92207f308b6bfb9235a33 (patch)
tree942748d28e820de56f73df8e6c58d2934a0c7b63 /Tools/parser
parent48238c7e373aed6bf0f246b6c0887827397ae5ce (diff)
parentd66dd5ce68cbf4a33c385439d5eeb2bff4e860f1 (diff)
downloadcpython-d07a1cb53b3d5b3b68b92207f308b6bfb9235a33.zip
cpython-d07a1cb53b3d5b3b68b92207f308b6bfb9235a33.tar.gz
cpython-d07a1cb53b3d5b3b68b92207f308b6bfb9235a33.tar.bz2
Issue #26489: Add dictionary unpacking support to Tools/parser/unparse.py
Patch by Guo Ci Teo.
Diffstat (limited to 'Tools/parser')
-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 35ebc66..7203057 100644
--- a/Tools/parser/unparse.py
+++ b/Tools/parser/unparse.py
@@ -456,12 +456,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):