diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -277,17 +277,16 @@ class CodeopTests(unittest.TestCase): ai("9+","eval") ai("lambda z:","eval") ai("a b","eval") ai("return 2.3") ai("if (a == 1 and b = 2): pass") ai("del 1") - ai("del ()") ai("del (1,)") ai("del [1]") ai("del '1'") ai("[i for i in range(10)] = (1, 2, 3)") def test_filename(self): self.assertEqual(compile_command("a = 1\n", "abc").co_filename, diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -30,24 +30,16 @@ Errors from set_context(): >>> obj.None = 1 Traceback (most recent call last): SyntaxError: invalid syntax >>> None = 1 Traceback (most recent call last): SyntaxError: can't assign to keyword -It's a syntax error to assign to the empty tuple. Why isn't it an -error to assign to the empty list? It will always raise some error at -runtime. - ->>> () = 1 -Traceback (most recent call last): -SyntaxError: can't assign to () - >>> f() = 1 Traceback (most recent call last): SyntaxError: can't assign to function call >>> del f() Traceback (most recent call last): SyntaxError: can't delete function call @@ -478,20 +470,16 @@ Make sure that the old "raise X, Y[, Z]" SyntaxError: invalid syntax >>> f(a=23, a=234) Traceback (most recent call last): ... SyntaxError: keyword argument repeated ->>> del () -Traceback (most recent call last): -SyntaxError: can't delete () - >>> {1, 2, 3} = 42 Traceback (most recent call last): SyntaxError: can't assign to literal Corner-cases that used to fail to raise the correct error: >>> def f(*, x=lambda __debug__:0): pass Traceback (most recent call last): diff --git a/Lib/test/test_tuple.py b/Lib/test/test_tuple.py --- a/Lib/test/test_tuple.py +++ b/Lib/test/test_tuple.py @@ -211,10 +211,18 @@ class TupleTest(seq_tests.CommonTest): def test_lexicographic_ordering(self): # Issue 21100 a = self.type2test([1, 2]) b = self.type2test([1, 2, 0]) c = self.type2test([1, 3]) self.assertLess(a, b) self.assertLess(b, c) + def test_empty_tuple_assignment(self): + () = [] + with self.assertRaisesRegex(ValueError, + 'too many values to unpack \(expected 0\)'): + () = [0] + with self.assertRaises(TypeError): + () = 42 + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py --- a/Lib/test/test_with.py +++ b/Lib/test/test_with.py @@ -135,21 +135,16 @@ class FailureTestCase(unittest.TestCase) self.assertRaises(SyntaxError, shouldRaiseSyntaxError, codestr) def testAssignmentToNoneError(self): self.assertRaisesSyntaxError('with mock as None:\n pass') self.assertRaisesSyntaxError( 'with mock as (None):\n' ' pass') - def testAssignmentToEmptyTupleError(self): - self.assertRaisesSyntaxError( - 'with mock as ():\n' - ' pass') - def testAssignmentToTupleOnlyContainingNoneError(self): self.assertRaisesSyntaxError('with mock as None,:\n pass') self.assertRaisesSyntaxError( 'with mock as (None,):\n' ' pass') def testAssignmentToTupleContainingNoneError(self): self.assertRaisesSyntaxError( diff --git a/Python/ast.c b/Python/ast.c --- a/Python/ast.c +++ b/Python/ast.c @@ -936,23 +936,18 @@ set_context(struct compiling *c, expr_ty } e->v.Name.ctx = ctx; break; case List_kind: e->v.List.ctx = ctx; s = e->v.List.elts; break; case Tuple_kind: - if (asdl_seq_LEN(e->v.Tuple.elts)) { - e->v.Tuple.ctx = ctx; - s = e->v.Tuple.elts; - } - else { - expr_name = "()"; - } + e->v.Tuple.ctx = ctx; + s = e->v.Tuple.elts; break; case Lambda_kind: expr_name = "lambda"; break; case Call_kind: expr_name = "function call"; break; case BoolOp_kind: