Kaydet (Commit) e62a694f authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Issue #26020: Fix evaluation order for set literals

üst cb20a217
......@@ -360,6 +360,21 @@ class TestSet(TestJointOps):
t = self.thetype(s)
self.assertNotEqual(id(s), id(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)
......
......@@ -2477,14 +2477,16 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
TARGET(BUILD_SET)
{
int i;
x = PySet_New(NULL);
if (x != NULL) {
for (; --oparg >= 0;) {
w = POP();
for (i = oparg; i > 0; i--) {
w = PEEK(i);
if (err == 0)
err = PySet_Add(x, w);
Py_DECREF(w);
}
STACKADJ(-oparg);
if (err != 0) {
Py_DECREF(x);
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment