mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #26489: Add dictionary unpacking support to Tools/parser/unparse.py
Patch by Guo Ci Teo.
This commit is contained in:
commit
d07a1cb53b
3 changed files with 20 additions and 3 deletions
|
@ -259,6 +259,11 @@ class UnparseTestCase(ASTTestCase):
|
||||||
def test_with_two_items(self):
|
def test_with_two_items(self):
|
||||||
self.check_roundtrip(with_two_items)
|
self.check_roundtrip(with_two_items)
|
||||||
|
|
||||||
|
def test_dict_unpacking_in_dict(self):
|
||||||
|
# See issue 26489
|
||||||
|
self.check_roundtrip(r"""{**{'y': 2}, 'x': 1}""")
|
||||||
|
self.check_roundtrip(r"""{**{'y': 2}, **{'x': 1}}""")
|
||||||
|
|
||||||
|
|
||||||
class DirectoryTestCase(ASTTestCase):
|
class DirectoryTestCase(ASTTestCase):
|
||||||
"""Test roundtrip behaviour on all files in Lib and Lib/test."""
|
"""Test roundtrip behaviour on all files in Lib and Lib/test."""
|
||||||
|
|
|
@ -828,6 +828,9 @@ Windows
|
||||||
Tools/Demos
|
Tools/Demos
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
- Issue #26489: Add dictionary unpacking support to Tools/parser/unparse.py.
|
||||||
|
Patch by Guo Ci Teo.
|
||||||
|
|
||||||
- Issue #26316: Fix variable name typo in Argument Clinic.
|
- Issue #26316: Fix variable name typo in Argument Clinic.
|
||||||
|
|
||||||
- Issue #25440: Fix output of python-config --extension-suffix.
|
- Issue #25440: Fix output of python-config --extension-suffix.
|
||||||
|
|
|
@ -456,12 +456,21 @@ class Unparser:
|
||||||
|
|
||||||
def _Dict(self, t):
|
def _Dict(self, t):
|
||||||
self.write("{")
|
self.write("{")
|
||||||
def write_pair(pair):
|
def write_key_value_pair(k, v):
|
||||||
(k, v) = pair
|
|
||||||
self.dispatch(k)
|
self.dispatch(k)
|
||||||
self.write(": ")
|
self.write(": ")
|
||||||
self.dispatch(v)
|
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("}")
|
self.write("}")
|
||||||
|
|
||||||
def _Tuple(self, t):
|
def _Tuple(self, t):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue