Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d66dd5ce
Commit
d66dd5ce
authored
Mar 06, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26489: Add dictionary unpacking support to Tools/parser/unparse.py
Patch by Guo Ci Teo.
parent
e88dd1c3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
3 deletions
+20
-3
Lib/test/test_tools/test_unparse.py
Lib/test/test_tools/test_unparse.py
+5
-0
Misc/NEWS
Misc/NEWS
+3
-0
Tools/parser/unparse.py
Tools/parser/unparse.py
+12
-3
No files found.
Lib/test/test_tools/test_unparse.py
View file @
d66dd5ce
...
...
@@ -250,6 +250,11 @@ class UnparseTestCase(ASTTestCase):
def
test_with_two_items
(
self
):
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
):
"""Test roundtrip behaviour on all files in Lib and Lib/test."""
...
...
Misc/NEWS
View file @
d66dd5ce
...
...
@@ -328,6 +328,9 @@ Windows
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
.
...
...
Tools/parser/unparse.py
View file @
d66dd5ce
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment