Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_syntax.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | f9f3950b5ec7 |
| children | 51102abdec50 |
| 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 TODO(jhylton): "assignment to None" is inconsistent with other messages |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
31 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
32 >>> obj.None = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
33 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
34 SyntaxError: assignment to None (<doctest test.test_syntax[1]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
35 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
36 >>> None = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
37 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
38 SyntaxError: assignment to None (<doctest test.test_syntax[2]>, line 1) |
|
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): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
46 SyntaxError: can't assign to () (<doctest test.test_syntax[3]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
47 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
48 >>> f() = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
49 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
50 SyntaxError: can't assign to function call (<doctest test.test_syntax[4]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
51 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
52 >>> del f() |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
53 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
54 SyntaxError: can't delete function call (<doctest test.test_syntax[5]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
55 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
56 >>> a + 1 = 2 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
57 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
58 SyntaxError: can't assign to operator (<doctest test.test_syntax[6]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
59 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
60 >>> (x for x in x) = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
61 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
62 SyntaxError: can't assign to generator expression (<doctest test.test_syntax[7]>, line 1) |
|
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 >>> 1 = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
65 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
66 SyntaxError: can't assign to literal (<doctest test.test_syntax[8]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
67 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
68 >>> "abc" = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
69 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
70 SyntaxError: can't assign to literal (<doctest test.test_syntax[9]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
71 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
72 >>> `1` = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
73 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
74 SyntaxError: can't assign to repr (<doctest test.test_syntax[10]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
75 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 them. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
80 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
81 >>> (a, "b", c) = (1, 2, 3) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
82 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
83 SyntaxError: can't assign to literal (<doctest test.test_syntax[11]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
84 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
85 >>> [a, b, c + 1] = [1, 2, 3] |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
86 Traceback (most recent call last): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
87 SyntaxError: can't assign to operator (<doctest test.test_syntax[12]>, line 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
88 |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
89 >>> 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
|
90 Traceback (most recent call last): |
|
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
91 SyntaxError: can't assign to conditional expression (<doctest test.test_syntax[13]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
92 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
93 From compiler_complex_args(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
94 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
95 >>> def f(None=1): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
96 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
97 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
98 SyntaxError: assignment to None (<doctest test.test_syntax[14]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
99 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
100 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
101 From ast_for_arguments(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
102 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
103 >>> def f(x, y=1, z): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
104 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
105 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
106 SyntaxError: non-default argument follows default argument (<doctest test.test_syntax[15]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
107 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
108 >>> def f(x, None): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
109 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
110 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
111 SyntaxError: assignment to None (<doctest test.test_syntax[16]>, line 1) |
|
36418
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 >>> def f(*None): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
114 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
115 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
116 SyntaxError: assignment to None (<doctest test.test_syntax[17]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
117 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
118 >>> def f(**None): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
119 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
120 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
121 SyntaxError: assignment to None (<doctest test.test_syntax[18]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
122 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
123 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
124 From ast_for_funcdef(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
125 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
126 >>> def None(x): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
127 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
128 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
129 SyntaxError: assignment to None (<doctest test.test_syntax[19]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
130 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
131 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
132 From ast_for_call(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
133 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
134 >>> def f(it, *varargs): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
135 ... return list(it) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
136 >>> L = range(10) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
137 >>> f(x for x in L) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
138 [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
|
139 >>> f(x for x in L, 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
140 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
141 SyntaxError: Generator expression must be parenthesized if not sole argument (<doctest test.test_syntax[23]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
142 >>> f((x for x in L), 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
143 [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
|
144 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
145 >>> 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
|
146 ... 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
|
147 ... 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
|
148 ... 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
|
149 ... 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
|
150 ... 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
|
151 ... 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
|
152 ... 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
|
153 ... 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
|
154 ... 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
|
155 ... 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
|
156 ... 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
|
157 ... 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
|
158 ... 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
|
159 ... 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
|
160 ... 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
|
161 ... 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
|
162 ... 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
|
163 ... 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
|
164 ... 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
|
165 ... 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
|
166 ... 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
|
167 ... 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
|
168 ... 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
|
169 ... 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
|
170 ... 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
|
171 ... i253, i254, i255) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
172 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
173 SyntaxError: more than 255 arguments (<doctest test.test_syntax[25]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
174 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
175 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
|
176 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
|
177 three. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
178 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
179 >>> 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
|
180 ... 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
|
181 ... 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
|
182 ... 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
|
183 ... 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
|
184 ... 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
|
185 ... 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
|
186 ... 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
|
187 ... 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
|
188 ... 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
|
189 ... 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
|
190 ... 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
|
191 ... 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
|
192 ... 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
|
193 ... 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
|
194 ... 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
|
195 ... 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
|
196 ... 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
|
197 ... 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
|
198 ... 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
|
199 ... 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
|
200 ... 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
|
201 ... 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
|
202 ... 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
|
203 ... 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
|
204 ... (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
|
205 ... i252=1, i253=1, i254=1, i255=1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
206 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
207 SyntaxError: more than 255 arguments (<doctest test.test_syntax[26]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
208 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
209 >>> f(lambda x: x[0] = 3) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
210 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
211 SyntaxError: lambda cannot contain assignment (<doctest test.test_syntax[27]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
212 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
213 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
|
214 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
|
215 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
216 >>> f(x()=2) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
217 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
218 SyntaxError: keyword can't be an expression (<doctest test.test_syntax[28]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
219 >>> f(a or b=1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
220 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
221 SyntaxError: keyword can't be an expression (<doctest test.test_syntax[29]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
222 >>> f(x.y=1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
223 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
224 SyntaxError: keyword can't be an expression (<doctest test.test_syntax[30]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
225 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
226 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
227 From ast_for_expr_stmt(): |
|
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 >>> (x for x in x) += 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
230 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
231 SyntaxError: augmented assignment to generator expression not possible (<doctest test.test_syntax[31]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
232 >>> None += 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
233 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
234 SyntaxError: assignment to None (<doctest test.test_syntax[32]>, line 1) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
235 >>> f() += 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
236 Traceback (most recent call last): |
|
38181
ab704b99e150
- Bug #1487966: Fix SystemError with conditional expression in assignment
Neal Norwitz <nnorwitz@gmail.com>
parents:
38111
diff
changeset
|
237 SyntaxError: illegal expression for augmented assignment (<doctest test.test_syntax[33]>, line 1) |
|
39611
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
238 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
239 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
240 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
|
241 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
242 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
|
243 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
244 >>> def test(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
245 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
246 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
247 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
248 ... for abc in range(10): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
249 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
250 ... print abc |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
251 >>> test() |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
252 9 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
253 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
254 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
|
255 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
256 >>> def test(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
257 ... for abc in range(10): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
258 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
259 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
260 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
261 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
262 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
263 ... |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
264 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[36]>, line 6) |
|
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 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
|
267 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
268 >>> def test(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
269 ... for abc in range(10): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
270 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
271 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
272 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
273 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
274 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
275 ... except: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
276 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
277 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
278 ... |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
279 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[37]>, line 7) |
|
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 >>> def foo(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
282 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
283 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
284 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
285 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
286 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
287 ... |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
288 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[38]>, line 5) |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
289 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
290 >>> def foo(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
291 ... for a in (): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
292 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
293 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
294 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
295 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
296 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
297 ... |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
298 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[39]>, line 6) |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
299 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
300 >>> def foo(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
301 ... for a in (): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
302 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
303 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
304 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
305 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
306 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
307 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
308 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
309 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
310 ... |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
311 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[40]>, line 7) |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
312 |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
313 >>> def foo(): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
314 ... for a in (): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
315 ... try: pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
316 ... finally: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
317 ... try: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
318 ... pass |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
319 ... except: |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
320 ... continue |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
321 Traceback (most recent call last): |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
322 ... |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
323 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[41]>, line 8) |
|
17f1df1553c9
Patch #1542451: disallow continue anywhere under a finally
Neal Norwitz <nnorwitz@gmail.com>
parents:
38218
diff
changeset
|
324 |
|
39983
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 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
|
329 |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
330 >>> try: |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
331 ... print 1 |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
332 ... break |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
333 ... print 2 |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
334 ... finally: |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
335 ... print 3 |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
336 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
|
337 ... |
|
f5d7de5031aa
Fix for SF bug 1569998: break permitted inside try.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
39611
diff
changeset
|
338 SyntaxError: 'break' outside loop (<doctest test.test_syntax[42]>, line 3) |
|
40227
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
339 |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
340 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
|
341 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
|
342 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
|
343 |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
344 >>> while 1: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
345 ... while 2: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
346 ... while 3: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
347 ... while 4: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
348 ... while 5: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
349 ... while 6: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
350 ... while 8: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
351 ... while 9: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
352 ... while 10: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
353 ... while 11: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
354 ... while 12: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
355 ... while 13: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
356 ... while 14: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
357 ... while 15: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
358 ... while 16: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
359 ... while 17: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
360 ... while 18: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
361 ... while 19: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
362 ... while 20: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
363 ... while 21: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
364 ... while 22: |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
365 ... break |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
366 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
|
367 ... |
|
3608605a74d5
Fix bug #1565514, SystemError not raised on too many nested blocks.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39983
diff
changeset
|
368 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
|
369 |
|
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
|
370 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
|
371 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
|
372 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
|
373 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
374 >>> 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
|
375 ... 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
|
376 ... 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
|
377 ... 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
|
378 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
|
379 ... |
|
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
|
380 SyntaxError: can't assign to function call (<doctest test.test_syntax[44]>, line 2) |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
381 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
382 >>> 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
|
383 ... 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
|
384 ... 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
|
385 ... 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
|
386 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
|
387 ... |
|
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
|
388 SyntaxError: can't assign to function call (<doctest test.test_syntax[45]>, line 4) |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
389 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
390 >>> 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
|
391 ... 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
|
392 ... 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
|
393 ... 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
|
394 ... 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
|
395 ... 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
|
396 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
|
397 ... |
|
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
|
398 SyntaxError: can't assign to function call (<doctest test.test_syntax[46]>, line 2) |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
399 |
|
b43a52f71696
Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements.
Collin Winter <collinw@gmail.com>
parents:
40227
diff
changeset
|
400 >>> 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
|
401 ... 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
|
402 ... 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
|
403 ... 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
|
404 ... 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
|
405 ... 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
|
406 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
|
407 ... |
|
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
|
408 SyntaxError: can't assign to function call (<doctest test.test_syntax[47]>, line 4) |
|
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 |
|
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 >>> 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
|
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 ... 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
|
413 ... 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
|
414 ... 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
|
415 ... 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
|
416 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
|
417 ... |
|
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
|
418 SyntaxError: can't assign to function call (<doctest test.test_syntax[48]>, line 6) |
|
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 |
|
47860
80109d4044cd
#3219 repeated keyword arguments aren't allowed in function calls anymore
Benjamin Peterson <benjamin@python.org>
parents:
41532
diff
changeset
|
420 >>> 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
|
421 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
|
422 ... |
|
80109d4044cd
#3219 repeated keyword arguments aren't allowed in function calls anymore
Benjamin Peterson <benjamin@python.org>
parents:
41532
diff
changeset
|
423 SyntaxError: keyword argument repeated (<doctest test.test_syntax[49]>, line 1) |
|
80109d4044cd
#3219 repeated keyword arguments aren't allowed in function calls anymore
Benjamin Peterson <benjamin@python.org>
parents:
41532
diff
changeset
|
424 |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
425 """ |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
426 |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
427 import re |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
428 import unittest |
|
29870
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
429 import warnings |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
430 |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23589
diff
changeset
|
431 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
|
432 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
433 class SyntaxTestCase(unittest.TestCase): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
434 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
435 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
|
436 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
|
437 """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
|
438 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 """ |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
443 try: |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
444 compile(code, filename, mode) |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
445 except SyntaxError, err: |
|
38111
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 if mo is None: |
|
57370
f9f3950b5ec7
Merged revisions 76416-76417 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48251
diff
changeset
|
450 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
|
451 else: |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
452 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
|
453 |
|
57370
f9f3950b5ec7
Merged revisions 76416-76417 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48251
diff
changeset
|
454 def test_paren_arg_with_default(self): |
|
f9f3950b5ec7
Merged revisions 76416-76417 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48251
diff
changeset
|
455 self._check_error("def f((x)=23): pass", |
|
f9f3950b5ec7
Merged revisions 76416-76417 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48251
diff
changeset
|
456 "parenthesized arg with default") |
|
f9f3950b5ec7
Merged revisions 76416-76417 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48251
diff
changeset
|
457 |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
458 def test_assign_call(self): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
459 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
|
460 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
461 def test_assign_del(self): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
462 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
|
463 |
|
29870
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
464 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
|
465 # 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
|
466 # 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
|
467 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
|
468 :def error(a): |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
469 : global a # SyntaxError |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
470 :def warning(): |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
471 : b = 1 |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
472 : global b # SyntaxWarning |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
473 :""") |
|
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
474 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
|
475 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
|
476 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
|
477 |
|
35959
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
478 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
|
479 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
|
480 |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
481 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
|
482 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
|
483 :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
|
484 : 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
|
485 : 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
|
486 : 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
|
487 :""") |
|
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
488 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
|
489 |
|
38111
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
490 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
|
491 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
|
492 subclass=IndentationError) |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
493 |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
494 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
|
495 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
|
496 subclass=IndentationError) |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
497 |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
498 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
|
499 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
|
500 "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
|
501 subclass=IndentationError) |
|
0e7d34aaea61
Patch #1475845: Raise IndentationError for unexpected indent.
Martin v. Löwis <martin@v.loewis.de>
parents:
36418
diff
changeset
|
502 |
|
38218
26fb563881c9
Fix #1474677, non-keyword argument following keyword.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38181
diff
changeset
|
503 def test_kwargs_last(self): |
|
26fb563881c9
Fix #1474677, non-keyword argument following keyword.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38181
diff
changeset
|
504 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
|
505 |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
506 def test_main(): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
507 test_support.run_unittest(SyntaxTestCase) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
508 from test import test_syntax |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
509 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
|
510 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
511 if __name__ == "__main__": |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
512 test_main() |
