Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
b4f8fd7e
Commit
b4f8fd7e
authored
May 22, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent PEP448 dict unpacking from leaking into first argument if it's a dict
parent
8b41a547
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
3 deletions
+88
-3
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+11
-3
tests/run/pep448_extended_unpacking.pyx
tests/run/pep448_extended_unpacking.pyx
+77
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
b4f8fd7e
...
@@ -5563,9 +5563,17 @@ class MergedDictNode(ExprNode):
...
@@ -5563,9 +5563,17 @@ class MergedDictNode(ExprNode):
code
.
putln
(
'if (likely(PyDict_CheckExact(%s))) {'
%
code
.
putln
(
'if (likely(PyDict_CheckExact(%s))) {'
%
item
.
py_result
())
item
.
py_result
())
item
.
make_owned_reference
(
code
)
if
item
.
is_dict_literal
:
code
.
putln
(
"%s = %s;"
%
(
self
.
result
(),
item
.
py_result
()))
item
.
make_owned_reference
(
code
)
item
.
generate_post_assignment_code
(
code
)
code
.
putln
(
"%s = %s;"
%
(
self
.
result
(),
item
.
py_result
()))
item
.
generate_post_assignment_code
(
code
)
else
:
code
.
putln
(
"%s = PyDict_Copy(%s); %s"
%
(
self
.
result
(),
item
.
py_result
(),
code
.
error_goto_if_null
(
self
.
result
(),
item
.
pos
)))
code
.
put_gotref
(
self
.
result
())
item
.
generate_disposal_code
(
code
)
if
item
.
type
is
not
dict_type
:
if
item
.
type
is
not
dict_type
:
code
.
putln
(
'} else {'
)
code
.
putln
(
'} else {'
)
...
...
tests/run/pep448_extended_unpacking.pyx
View file @
b4f8fd7e
...
@@ -117,6 +117,33 @@ def unpack_tuple_from_iterable(it):
...
@@ -117,6 +117,33 @@ def unpack_tuple_from_iterable(it):
return
(
1
,
2
,
*
it
,
1
,
*
(
*
it
,
*
it
),
*
it
,
2
,
1
,
*
it
)
return
(
1
,
2
,
*
it
,
1
,
*
(
*
it
,
*
it
),
*
it
,
2
,
1
,
*
it
)
def
unpack_tuple_keep_originals
(
a
,
b
,
c
):
"""
>>> a = b = [1, 2]
>>> c = [3, 4]
>>> unpack_tuple_keep_originals(a, b, c)
(1, 2, 1, 2, 2, 3, 4)
>>> a
[1, 2]
>>> b
[1, 2]
>>> c
[3, 4]
>>> a = b = (1, 2)
>>> c = (3, 4)
>>> unpack_tuple_keep_originals(a, b, c)
(1, 2, 1, 2, 2, 3, 4)
>>> a
(1, 2)
>>> b
(1, 2)
>>> c
(3, 4)
"""
return
(
*
a
,
*
b
,
2
,
*
c
)
#### lists
#### lists
...
@@ -211,6 +238,22 @@ def unpack_list_from_iterable(it):
...
@@ -211,6 +238,22 @@ def unpack_list_from_iterable(it):
return
[
1
,
2
,
*
it
,
1
,
*
[
*
it
,
*
it
],
*
it
,
2
,
1
,
*
it
]
return
[
1
,
2
,
*
it
,
1
,
*
[
*
it
,
*
it
],
*
it
,
2
,
1
,
*
it
]
def
unpack_list_keep_originals
(
a
,
b
,
c
):
"""
>>> a = b = [1, 2]
>>> c = [3, 4]
>>> unpack_list_keep_originals(a, b, c)
[1, 2, 1, 2, 2, 3, 4]
>>> a
[1, 2]
>>> b
[1, 2]
>>> c
[3, 4]
"""
return
[
*
a
,
*
b
,
2
,
*
c
]
###### sets
###### sets
...
@@ -321,6 +364,23 @@ def unpack_set_from_iterable(it):
...
@@ -321,6 +364,23 @@ def unpack_set_from_iterable(it):
return
{
1
,
2
,
*
it
,
1
,
*
{
*
it
,
*
it
},
*
it
,
2
,
1
,
*
it
,
*
it
}
return
{
1
,
2
,
*
it
,
1
,
*
{
*
it
,
*
it
},
*
it
,
2
,
1
,
*
it
,
*
it
}
def
unpack_set_keep_originals
(
a
,
b
,
c
):
"""
>>> a = b = {1, 2}
>>> c = {3, 4}
>>> s = unpack_set_keep_originals(a, b, c)
>>> s == set([1, 2, 3, 4]) or s
True
>>> a == set([1, 2]) or a
True
>>> b == set([1, 2]) or b
True
>>> c == set([3, 4]) or c
True
"""
return
{
*
a
,
*
b
,
2
,
*
c
}
#### dicts
#### dicts
...
@@ -441,3 +501,20 @@ def unpack_dict_from_iterable(it):
...
@@ -441,3 +501,20 @@ def unpack_dict_from_iterable(it):
True
True
"""
"""
return
{
'a'
:
2
,
'b'
:
3
,
**
it
,
'a'
:
1
,
**
{
**
it
,
**
it
},
**
it
,
'a'
:
4
,
'b'
:
5
,
**
it
,
**
it
}
return
{
'a'
:
2
,
'b'
:
3
,
**
it
,
'a'
:
1
,
**
{
**
it
,
**
it
},
**
it
,
'a'
:
4
,
'b'
:
5
,
**
it
,
**
it
}
def
unpack_dict_keep_originals
(
a
,
b
,
c
):
"""
>>> a = b = {1: 2}
>>> c = {2: 3, 4: 5}
>>> d = unpack_dict_keep_originals(a, b, c)
>>> d == {1: 2, 2: 3, 4: 5} or d
True
>>> a
{1: 2}
>>> b
{1: 2}
>>> c == {2: 3, 4: 5} or c
True
"""
return
{
**
a
,
**
b
,
2
:
4
,
**
c
}
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