diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -267,11 +267,23 @@ asm = disassemble(f) self.assertNotIn('BINARY_ADD', asm) +class TestBuglets(unittest.TestCase): + + def test_bug_11510(self): + # folded constant set optimization was commingled with the tuple + # unpacking optimization which would fail if the set had duplicate + # elements so that the set length was unexpected + def f(): + x, y = {1, 1} + return x, y + with self.assertRaises(ValueError): + f() + def test_main(verbose=None): import sys from test import support - test_classes = (TestTranforms,) + test_classes = (TestTranforms, TestBuglets) support.run_unittest(*test_classes) # verify reference counting diff --git a/Python/peephole.c b/Python/peephole.c --- a/Python/peephole.c +++ b/Python/peephole.c @@ -473,6 +473,8 @@ cumlc = 1; break; } + if (opcode == BUILD_SET) + continue; if (codestr[i+3] != UNPACK_SEQUENCE || !ISBASICBLOCK(blocks,i,6) || j != GETARG(codestr, i+3))