Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_syntax.py @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 0dd1aa33265f |
| children | c8c840162804 |
| rev | line source |
|---|---|
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
1 """This module tests SyntaxErrors. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
2 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
3 Here's an example of the sort of thing that is tested. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
4 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
5 >>> def f(x): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
6 ... global x |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
7 Traceback (most recent call last): |
|
48251
2d76af7f7702
include filename and line number in SyntaxError
Benjamin Peterson <benjamin@python.org>
parents:
47860
diff
changeset
|
8 SyntaxError: name 'x' is local and global (<doctest test.test_syntax[0]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
9 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
10 The tests are all raise SyntaxErrors. They were created by checking |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
11 each C call that raises SyntaxError. There are several modules that |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
12 raise these exceptions-- ast.c, compile.c, future.c, pythonrun.c, and |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
13 symtable.c. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
14 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
15 The parser itself outlaws a lot of invalid syntax. None of these |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
16 errors are tested here at the moment. We should add some tests; since |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
17 there are infinitely many programs with invalid syntax, we would need |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
18 to be judicious in selecting some. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
19 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
20 The compiler generates a synthetic module name for code executed by |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
21 doctest. Since all the code comes from the same module, a suffix like |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
22 [1] is appended to the module name, As a consequence, changing the |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
23 order of tests in this module means renumbering all the errors after |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
24 it. (Maybe we should enable the ellipsis option for these tests.) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
25 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
26 In ast.c, syntax errors are raised by calling ast_error(). |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
27 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
28 Errors from set_context(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
29 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
30 >>> obj.None = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
31 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
32 File "<doctest test.test_syntax[1]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
33 SyntaxError: cannot assign to None |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
34 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
35 >>> None = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
36 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
37 File "<doctest test.test_syntax[2]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
38 SyntaxError: cannot assign to None |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
39 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
40 It's a syntax error to assign to the empty tuple. Why isn't it an |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
41 error to assign to the empty list? It will always raise some error at |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
42 runtime. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
43 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
44 >>> () = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
45 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
46 File "<doctest test.test_syntax[3]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
47 SyntaxError: can't assign to () |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
48 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
49 >>> f() = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
50 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
51 File "<doctest test.test_syntax[4]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
52 SyntaxError: can't assign to function call |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
53 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
54 >>> del f() |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
55 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
56 File "<doctest test.test_syntax[5]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
57 SyntaxError: can't delete function call |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
58 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
59 >>> a + 1 = 2 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
60 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
61 File "<doctest test.test_syntax[6]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
62 SyntaxError: can't assign to operator |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
63 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
64 >>> (x for x in x) = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
65 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
66 File "<doctest test.test_syntax[7]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
67 SyntaxError: can't assign to generator expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
68 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
69 >>> 1 = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
70 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
71 File "<doctest test.test_syntax[8]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
72 SyntaxError: can't assign to literal |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
73 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
74 >>> "abc" = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
75 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
76 File "<doctest test.test_syntax[8]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
77 SyntaxError: can't assign to literal |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
78 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
79 >>> `1` = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
80 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
81 File "<doctest test.test_syntax[10]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
82 SyntaxError: can't assign to repr |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
83 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
84 If the left-hand side of an assignment is a list or tuple, an illegal |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
85 expression inside that contain should still cause a syntax error. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
86 This test just checks a couple of cases rather than enumerating all of |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
87 them. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
88 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
89 >>> (a, "b", c) = (1, 2, 3) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
90 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
91 File "<doctest test.test_syntax[11]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
92 SyntaxError: can't assign to literal |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
93 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
94 >>> [a, b, c + 1] = [1, 2, 3] |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
95 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
96 File "<doctest test.test_syntax[12]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
97 SyntaxError: can't assign to operator |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
98 |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
99 >>> a if 1 else b = 1 |
|
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
100 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
101 File "<doctest test.test_syntax[13]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
102 SyntaxError: can't assign to conditional expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
103 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
104 From compiler_complex_args(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
105 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
106 >>> def f(None=1): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
107 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
108 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
109 File "<doctest test.test_syntax[14]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
110 SyntaxError: cannot assign to None |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
111 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
112 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
113 From ast_for_arguments(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
114 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
115 >>> def f(x, y=1, z): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
116 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
117 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
118 File "<doctest test.test_syntax[15]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
119 SyntaxError: non-default argument follows default argument |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
120 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
121 >>> def f(x, None): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
122 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
123 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
124 File "<doctest test.test_syntax[16]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
125 SyntaxError: cannot assign to None |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
126 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
127 >>> def f(*None): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
128 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
129 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
130 File "<doctest test.test_syntax[17]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
131 SyntaxError: cannot assign to None |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
132 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
133 >>> def f(**None): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
134 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
135 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
136 File "<doctest test.test_syntax[18]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
137 SyntaxError: cannot assign to None |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
138 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
139 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
140 From ast_for_funcdef(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
141 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
142 >>> def None(x): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
143 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
144 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
145 File "<doctest test.test_syntax[19]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
146 SyntaxError: cannot assign to None |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
147 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
148 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
149 From ast_for_call(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
150 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
151 >>> def f(it, *varargs): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
152 ... return list(it) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
153 >>> L = range(10) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
154 >>> f(x for x in L) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
155 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
156 >>> f(x for x in L, 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
157 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
158 File "<doctest test.test_syntax[23]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
159 SyntaxError: Generator expression must be parenthesized if not sole argument |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
160 >>> f((x for x in L), 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
161 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
162 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
163 >>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
164 ... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
165 ... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
166 ... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
167 ... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
168 ... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
169 ... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
170 ... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
171 ... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
172 ... i100, i101, i102, i103, i104, i105, i106, i107, i108, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
173 ... i109, i110, i111, i112, i113, i114, i115, i116, i117, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
174 ... i118, i119, i120, i121, i122, i123, i124, i125, i126, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
175 ... i127, i128, i129, i130, i131, i132, i133, i134, i135, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
176 ... i136, i137, i138, i139, i140, i141, i142, i143, i144, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
177 ... i145, i146, i147, i148, i149, i150, i151, i152, i153, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
178 ... i154, i155, i156, i157, i158, i159, i160, i161, i162, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
179 ... i163, i164, i165, i166, i167, i168, i169, i170, i171, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
180 ... i172, i173, i174, i175, i176, i177, i178, i179, i180, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
181 ... i181, i182, i183, i184, i185, i186, i187, i188, i189, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
182 ... i190, i191, i192, i193, i194, i195, i196, i197, i198, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
183 ... i199, i200, i201, i202, i203, i204, i205, i206, i207, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
184 ... i208, i209, i210, i211, i212, i213, i214, i215, i216, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
185 ... i217, i218, i219, i220, i221, i222, i223, i224, i225, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
186 ... i226, i227, i228, i229, i230, i231, i232, i233, i234, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
187 ... i235, i236, i237, i238, i239, i240, i241, i242, i243, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
188 ... i244, i245, i246, i247, i248, i249, i250, i251, i252, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
189 ... i253, i254, i255) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
190 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
191 File "<doctest test.test_syntax[25]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
192 SyntaxError: more than 255 arguments |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
193 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
194 The actual error cases counts positional arguments, keyword arguments, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
195 and generator expression arguments separately. This test combines the |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
196 three. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
197 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
198 >>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
199 ... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
200 ... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
201 ... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
202 ... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
203 ... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
204 ... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
205 ... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
206 ... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
207 ... i100, i101, i102, i103, i104, i105, i106, i107, i108, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
208 ... i109, i110, i111, i112, i113, i114, i115, i116, i117, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
209 ... i118, i119, i120, i121, i122, i123, i124, i125, i126, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
210 ... i127, i128, i129, i130, i131, i132, i133, i134, i135, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
211 ... i136, i137, i138, i139, i140, i141, i142, i143, i144, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
212 ... i145, i146, i147, i148, i149, i150, i151, i152, i153, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
213 ... i154, i155, i156, i157, i158, i159, i160, i161, i162, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
214 ... i163, i164, i165, i166, i167, i168, i169, i170, i171, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
215 ... i172, i173, i174, i175, i176, i177, i178, i179, i180, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
216 ... i181, i182, i183, i184, i185, i186, i187, i188, i189, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
217 ... i190, i191, i192, i193, i194, i195, i196, i197, i198, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
218 ... i199, i200, i201, i202, i203, i204, i205, i206, i207, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
219 ... i208, i209, i210, i211, i212, i213, i214, i215, i216, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
220 ... i217, i218, i219, i220, i221, i222, i223, i224, i225, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
221 ... i226, i227, i228, i229, i230, i231, i232, i233, i234, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
222 ... i235, i236, i237, i238, i239, i240, i241, i242, i243, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
223 ... (x for x in i244), i245, i246, i247, i248, i249, i250, i251, |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
224 ... i252=1, i253=1, i254=1, i255=1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
225 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
226 File "<doctest test.test_syntax[26]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
227 SyntaxError: more than 255 arguments |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
228 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
229 >>> f(lambda x: x[0] = 3) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
230 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
231 File "<doctest test.test_syntax[27]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
232 SyntaxError: lambda cannot contain assignment |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
233 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
234 The grammar accepts any test (basically, any expression) in the |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
235 keyword slot of a call site. Test a few different options. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
236 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
237 >>> f(x()=2) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
238 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
239 File "<doctest test.test_syntax[28]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
240 SyntaxError: keyword can't be an expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
241 >>> f(a or b=1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
242 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
243 File "<doctest test.test_syntax[29]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
244 SyntaxError: keyword can't be an expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
245 >>> f(x.y=1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
246 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
247 File "<doctest test.test_syntax[30]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
248 SyntaxError: keyword can't be an expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
249 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
250 |
|
54639
1b8602c38fd0
remove error checks already done in set_context()
Benjamin Peterson <benjamin@python.org>
parents:
52956
diff
changeset
|
251 More set_context(): |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
252 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
253 >>> (x for x in x) += 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
254 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
255 File "<doctest test.test_syntax[31]>", line 1 |
|
54639
1b8602c38fd0
remove error checks already done in set_context()
Benjamin Peterson <benjamin@python.org>
parents:
52956
diff
changeset
|
256 SyntaxError: can't assign to generator expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
257 >>> None += 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
258 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
259 File "<doctest test.test_syntax[32]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
260 SyntaxError: cannot assign to None |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
261 >>> f() += 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
262 Traceback (most recent call last): |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
263 File "<doctest test.test_syntax[33]>", line 1 |
|
54639
1b8602c38fd0
remove error checks already done in set_context()
Benjamin Peterson <benjamin@python.org>
parents:
52956
diff
changeset
|
264 SyntaxError: can't assign to function call |
|
39611
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
265 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
266 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
267 Test continue in finally in weird combinations. |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
268 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
269 continue in for loop under finally shouuld be ok. |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
270 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
271 >>> def test(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
272 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
273 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
274 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
275 ... for abc in range(10): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
276 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
277 ... print abc |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
278 >>> test() |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
279 9 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
280 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
281 Start simple, a continue in a finally should not be allowed. |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
282 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
283 >>> def test(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
284 ... for abc in range(10): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
285 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
286 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
287 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
288 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
289 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
290 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
291 File "<doctest test.test_syntax[36]>", line 6 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
292 SyntaxError: 'continue' not supported inside 'finally' clause |
|
39611
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
293 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
294 This is essentially a continue in a finally which should not be allowed. |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
295 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
296 >>> def test(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
297 ... for abc in range(10): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
298 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
299 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
300 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
301 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
302 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
303 ... except: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
304 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
305 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
306 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
307 File "<doctest test.test_syntax[37]>", line 6 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
308 SyntaxError: 'continue' not supported inside 'finally' clause |
|
39611
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
309 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
310 >>> def foo(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
311 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
312 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
313 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
314 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
315 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
316 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
317 File "<doctest test.test_syntax[38]>", line 5 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
318 SyntaxError: 'continue' not supported inside 'finally' clause |
|
39611
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
319 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
320 >>> def foo(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
321 ... for a in (): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
322 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
323 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
324 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
325 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
326 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
327 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
328 File "<doctest test.test_syntax[39]>", line 6 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
329 SyntaxError: 'continue' not supported inside 'finally' clause |
|
39611
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
330 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
331 >>> def foo(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
332 ... for a in (): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
333 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
334 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
335 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
336 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
337 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
338 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
339 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
340 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
341 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
342 File "<doctest test.test_syntax[40]>", line 7 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
343 SyntaxError: 'continue' not supported inside 'finally' clause |
|
39611
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
344 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
345 >>> def foo(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
346 ... for a in (): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
347 ... try: pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
348 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
349 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
350 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
351 ... except: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
352 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
353 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
354 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
355 File "<doctest test.test_syntax[41]>", line 8 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
356 SyntaxError: 'continue' not supported inside 'finally' clause |
|
39611
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
357 |
|
39983
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
358 There is one test for a break that is not in a loop. The compiler |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
359 uses a single data structure to keep track of try-finally and loops, |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
360 so we need to be sure that a break is actually inside a loop. If it |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
361 isn't, there should be a syntax error. |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
362 |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
363 >>> try: |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
364 ... print 1 |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
365 ... break |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
366 ... print 2 |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
367 ... finally: |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
368 ... print 3 |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
369 Traceback (most recent call last): |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
370 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
371 File "<doctest test.test_syntax[42]>", line 3 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
372 SyntaxError: 'break' outside loop |
|
40227
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
373 |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
374 This should probably raise a better error than a SystemError (or none at all). |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
375 In 2.5 there was a missing exception and an assert was triggered in a debug |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
376 build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514 |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
377 |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
378 >>> while 1: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
379 ... while 2: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
380 ... while 3: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
381 ... while 4: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
382 ... while 5: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
383 ... while 6: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
384 ... while 8: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
385 ... while 9: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
386 ... while 10: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
387 ... while 11: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
388 ... while 12: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
389 ... while 13: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
390 ... while 14: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
391 ... while 15: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
392 ... while 16: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
393 ... while 17: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
394 ... while 18: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
395 ... while 19: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
396 ... while 20: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
397 ... while 21: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
398 ... while 22: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
399 ... break |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
400 Traceback (most recent call last): |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
401 ... |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
402 SystemError: too many statically nested blocks |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
403 |
|
41205
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
404 This tests assignment-context; there was a bug in Python 2.5 where compiling |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
405 a complex 'if' (one with 'elif') would fail to notice an invalid suite, |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
406 leading to spurious errors. |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
407 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
408 >>> if 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
409 ... x() = 1 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
410 ... elif 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
411 ... pass |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
412 Traceback (most recent call last): |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41205
diff
changeset
|
413 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
414 File "<doctest test.test_syntax[44]>", line 2 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
415 SyntaxError: can't assign to function call |
|
41205
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
416 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
417 >>> if 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
418 ... pass |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
419 ... elif 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
420 ... x() = 1 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
421 Traceback (most recent call last): |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41205
diff
changeset
|
422 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
423 File "<doctest test.test_syntax[45]>", line 4 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
424 SyntaxError: can't assign to function call |
|
41205
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
425 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
426 >>> if 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
427 ... x() = 1 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
428 ... elif 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
429 ... pass |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
430 ... else: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
431 ... pass |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
432 Traceback (most recent call last): |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41205
diff
changeset
|
433 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
434 File "<doctest test.test_syntax[46]>", line 2 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
435 SyntaxError: can't assign to function call |
|
41205
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
436 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
437 >>> if 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
438 ... pass |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
439 ... elif 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
440 ... x() = 1 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
441 ... else: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
442 ... pass |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
443 Traceback (most recent call last): |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41205
diff
changeset
|
444 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
445 File "<doctest test.test_syntax[47]>", line 4 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
446 SyntaxError: can't assign to function call |
|
41205
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
447 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
448 >>> if 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
449 ... pass |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
450 ... elif 1: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
451 ... pass |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
452 ... else: |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
453 ... x() = 1 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
454 Traceback (most recent call last): |
|
41532
4b9fa8092e82
Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents:
41205
diff
changeset
|
455 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
456 File "<doctest test.test_syntax[48]>", line 6 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
457 SyntaxError: can't assign to function call |
|
41205
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
458 |
|
47860
80109d4044cd
#3219 repeated keyword arguments aren't allowed in function calls anymore
Benjamin Peterson <benjamin@python.org>
parents:
41532
diff
changeset
|
459 >>> f(a=23, a=234) |
|
80109d4044cd
#3219 repeated keyword arguments aren't allowed in function calls anymore
Benjamin Peterson <benjamin@python.org>
parents:
41532
diff
changeset
|
460 Traceback (most recent call last): |
|
80109d4044cd
#3219 repeated keyword arguments aren't allowed in function calls anymore
Benjamin Peterson <benjamin@python.org>
parents:
41532
diff
changeset
|
461 ... |
|
52956
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
462 File "<doctest test.test_syntax[49]>", line 1 |
|
b50f11b8cad7
fix syntax tests after formatting change
Benjamin Peterson <benjamin@python.org>
parents:
49696
diff
changeset
|
463 SyntaxError: keyword argument repeated |
|
47860
80109d4044cd
#3219 repeated keyword arguments aren't allowed in function calls anymore
Benjamin Peterson <benjamin@python.org>
parents:
41532
diff
changeset
|
464 |
|
54742
3eb8510808c9
give a better error message when deleting ()
Benjamin Peterson <benjamin@python.org>
parents:
54639
diff
changeset
|
465 >>> del () |
|
3eb8510808c9
give a better error message when deleting ()
Benjamin Peterson <benjamin@python.org>
parents:
54639
diff
changeset
|
466 Traceback (most recent call last): |
|
3eb8510808c9
give a better error message when deleting ()
Benjamin Peterson <benjamin@python.org>
parents:
54639
diff
changeset
|
467 ... |
|
3eb8510808c9
give a better error message when deleting ()
Benjamin Peterson <benjamin@python.org>
parents:
54639
diff
changeset
|
468 File "<doctest test.test_syntax[50]>", line 1 |
|
3eb8510808c9
give a better error message when deleting ()
Benjamin Peterson <benjamin@python.org>
parents:
54639
diff
changeset
|
469 SyntaxError: can't delete () |
|
3eb8510808c9
give a better error message when deleting ()
Benjamin Peterson <benjamin@python.org>
parents:
54639
diff
changeset
|
470 |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
471 """ |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
472 |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
473 import re |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
474 import unittest |
|
29870
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
475 import warnings |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
476 |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23589
diff
changeset
|
477 from test import test_support |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
478 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
479 class SyntaxTestCase(unittest.TestCase): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
480 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
481 def _check_error(self, code, errtext, |
|
38111
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
482 filename="<testcase>", mode="exec", subclass=None): |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
483 """Check that compiling code raises SyntaxError with errtext. |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
484 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
485 errtest is a regular expression that must be present in the |
|
38111
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
486 test of the exception raised. If subclass is specified it |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
487 is the expected subclass of SyntaxError (e.g. IndentationError). |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
488 """ |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
489 try: |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
490 compile(code, filename, mode) |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
491 except SyntaxError, err: |
|
38111
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
492 if subclass and not isinstance(err, subclass): |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
493 self.fail("SyntaxError is not a %s" % subclass.__name__) |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
494 mo = re.search(errtext, str(err)) |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
495 if mo is None: |
|
57367
ed30bcffa146
improve several corner cases related with argument names in parenthesis
Benjamin Peterson <benjamin@python.org>
parents:
54742
diff
changeset
|
496 self.fail("%s did not contain '%r'" % (err, errtext,)) |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
497 else: |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
498 self.fail("compile() did not raise SyntaxError") |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
499 |
|
57367
ed30bcffa146
improve several corner cases related with argument names in parenthesis
Benjamin Peterson <benjamin@python.org>
parents:
54742
diff
changeset
|
500 def test_paren_arg_with_default(self): |
|
ed30bcffa146
improve several corner cases related with argument names in parenthesis
Benjamin Peterson <benjamin@python.org>
parents:
54742
diff
changeset
|
501 self._check_error("def f((x)=23): pass", |
|
ed30bcffa146
improve several corner cases related with argument names in parenthesis
Benjamin Peterson <benjamin@python.org>
parents:
54742
diff
changeset
|
502 "parenthesized arg with default") |
|
ed30bcffa146
improve several corner cases related with argument names in parenthesis
Benjamin Peterson <benjamin@python.org>
parents:
54742
diff
changeset
|
503 |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
504 def test_assign_call(self): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
505 self._check_error("f() = 1", "assign") |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
506 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
507 def test_assign_del(self): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
508 self._check_error("del f()", "delete") |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
509 |
|
29870
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
510 def test_global_err_then_warn(self): |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
511 # Bug tickler: The SyntaxError raised for one global statement |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
512 # shouldn't be clobbered by a SyntaxWarning issued for a later one. |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
513 source = re.sub('(?m)^ *:', '', """\ |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
514 :def error(a): |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
515 : global a # SyntaxError |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
516 :def warning(): |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
517 : b = 1 |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
518 : global b # SyntaxWarning |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
519 :""") |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
520 warnings.filterwarnings(action='ignore', category=SyntaxWarning) |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
521 self._check_error(source, "global") |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
522 warnings.filters.pop(0) |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
523 |
|
35959
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
524 def test_break_outside_loop(self): |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
525 self._check_error("break", "outside loop") |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
526 |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
527 def test_delete_deref(self): |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
528 source = re.sub('(?m)^ *:', '', """\ |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
529 :def foo(x): |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
530 : def bar(): |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
531 : print x |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
532 : del x |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
533 :""") |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
534 self._check_error(source, "nested scope") |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
535 |
|
38111
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
536 def test_unexpected_indent(self): |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
537 self._check_error("foo()\n bar()\n", "unexpected indent", |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
538 subclass=IndentationError) |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
539 |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
540 def test_no_indent(self): |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
541 self._check_error("if 1:\nfoo()", "expected an indented block", |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
542 subclass=IndentationError) |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
543 |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
544 def test_bad_outdent(self): |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
545 self._check_error("if 1:\n foo()\n bar()", |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
546 "unindent does not match .* level", |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
547 subclass=IndentationError) |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
548 |
|
38218
26fb563881c9
Fix #1474677, non-keyword argument following keyword.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38181
diff
changeset
|
549 def test_kwargs_last(self): |
|
26fb563881c9
Fix #1474677, non-keyword argument following keyword.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38181
diff
changeset
|
550 self._check_error("int(base=10, '2')", "non-keyword arg") |
|
26fb563881c9
Fix #1474677, non-keyword argument following keyword.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38181
diff
changeset
|
551 |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
552 def test_main(): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
553 test_support.run_unittest(SyntaxTestCase) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
554 from test import test_syntax |
|
58198
0dd1aa33265f
Reverting the Revision: 77368. I committed Flox's big patch for tests by
Senthil Kumaran <orsenthil@gmail.com>
parents:
58197
diff
changeset
|
555 test_support.run_doctest(test_syntax, verbosity=True) |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
556 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
557 if __name__ == "__main__": |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
558 test_main() |
