summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-09-08 21:40:36 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-09-08 21:40:36 (GMT)
commit262b6793e04993cb88847a3fb8dab22848cf6647 (patch)
tree7b985de4d19e233277cfbd767eb71b11034429e9 /Lib
parent5dc504c3c937a160c6d09bb124df5298712a1839 (diff)
downloadcpython-262b6793e04993cb88847a3fb8dab22848cf6647.zip
cpython-262b6793e04993cb88847a3fb8dab22848cf6647.tar.gz
cpython-262b6793e04993cb88847a3fb8dab22848cf6647.tar.bz2
Issue #26020: Fix evaluation order for set literals
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_set.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 1a49edf..7594303 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -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)