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
262b6793
Commit
262b6793
authored
Sep 08, 2016
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26020: Fix evaluation order for set literals
parent
5dc504c3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
2 deletions
+21
-2
Lib/test/test_set.py
Lib/test/test_set.py
+15
-0
Misc/NEWS
Misc/NEWS
+2
-0
Python/ceval.c
Python/ceval.c
+4
-2
No files found.
Lib/test/test_set.py
View file @
262b6793
...
...
@@ -388,6 +388,21 @@ class TestSet(TestJointOps, unittest.TestCase):
t
=
{
1
,
2
,
3
}
self
.
assertEqual
(
s
,
t
)
def
test_set_literal_insertion_order
(
self
):
# SF Issue #26020 -- Expect left to right insertion
s
=
{
1
,
1.0
,
True
}
self
.
assertEqual
(
len
(
s
),
1
)
stored_value
=
s
.
pop
()
self
.
assertEqual
(
type
(
stored_value
),
int
)
def
test_set_literal_evaluation_order
(
self
):
# Expect left to right expression evaluation
events
=
[]
def
record
(
obj
):
events
.
append
(
obj
)
s
=
{
record
(
1
),
record
(
2
),
record
(
3
)}
self
.
assertEqual
(
events
,
[
1
,
2
,
3
])
def
test_hash
(
self
):
self
.
assertRaises
(
TypeError
,
hash
,
self
.
s
)
...
...
Misc/NEWS
View file @
262b6793
...
...
@@ -20,6 +20,8 @@ Core and Builtins
after use of '
def
' in _PyState_AddModule().
Initial patch by Christian Heimes.
- Issue #26020: set literal evaluation order did not match documented behaviour.
- Issue #27782: Multi-phase extension module import now correctly allows the
``m_methods`` field to be used to add module level functions to instances
of non-module types returned from ``Py_create_mod``. Patch by Xiang Zhang.
...
...
Python/ceval.c
View file @
262b6793
...
...
@@ -2580,14 +2580,16 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
TARGET
(
BUILD_SET
)
{
PyObject
*
set
=
PySet_New
(
NULL
);
int
err
=
0
;
int
i
;
if
(
set
==
NULL
)
goto
error
;
while
(
--
oparg
>=
0
)
{
PyObject
*
item
=
P
OP
(
);
for
(
i
=
oparg
;
i
>
0
;
i
--
)
{
PyObject
*
item
=
P
EEK
(
i
);
if
(
err
==
0
)
err
=
PySet_Add
(
set
,
item
);
Py_DECREF
(
item
);
}
STACKADJ
(
-
oparg
);
if
(
err
!=
0
)
{
Py_DECREF
(
set
);
goto
error
;
...
...
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