Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_syntax.py @ 70817:dd775b1561ba
Fix markup.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 14 Jun 2011 21:09:55 +0200 |
| parents | d25c2812b0d8 |
| children | 03f92a9f0875 |
| 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): |
|
41464
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
40965
diff
changeset
|
8 SyntaxError: name 'x' is parameter and global |
|
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): |
|
41969
9d02a4adf574
Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
32 SyntaxError: invalid syntax |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
33 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
34 >>> None = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
35 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
36 SyntaxError: assignment to keyword |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
37 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
38 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
|
39 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
|
40 runtime. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
41 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
42 >>> () = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
43 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
44 SyntaxError: can't assign to () |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
45 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
46 >>> f() = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
47 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
48 SyntaxError: can't assign to function call |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
49 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
50 >>> del f() |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
51 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
52 SyntaxError: can't delete 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 >>> a + 1 = 2 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
55 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
56 SyntaxError: can't assign to operator |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
57 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
58 >>> (x for x in x) = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
59 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
60 SyntaxError: can't assign to generator expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
61 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
62 >>> 1 = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
63 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
64 SyntaxError: can't assign to literal |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
65 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
66 >>> "abc" = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
67 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
68 SyntaxError: can't assign to literal |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
69 |
|
69288
4d9a8e84279a
make assigning to a bytes literal a syntax error (closes #11506)
Benjamin Peterson <benjamin@python.org>
parents:
68585
diff
changeset
|
70 >>> b"" = 1 |
|
4d9a8e84279a
make assigning to a bytes literal a syntax error (closes #11506)
Benjamin Peterson <benjamin@python.org>
parents:
68585
diff
changeset
|
71 Traceback (most recent call last): |
|
4d9a8e84279a
make assigning to a bytes literal a syntax error (closes #11506)
Benjamin Peterson <benjamin@python.org>
parents:
68585
diff
changeset
|
72 SyntaxError: can't assign to literal |
|
4d9a8e84279a
make assigning to a bytes literal a syntax error (closes #11506)
Benjamin Peterson <benjamin@python.org>
parents:
68585
diff
changeset
|
73 |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
74 >>> `1` = 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
75 Traceback (most recent call last): |
|
39674
6927acbfa01b
Change test of assignment of backticked expression to be an "invalid syntax"
Brett Cannon <bcannon@gmail.com>
parents:
38453
diff
changeset
|
76 SyntaxError: invalid syntax |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
77 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
78 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
|
79 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
|
80 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
|
81 them. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
82 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
83 >>> (a, "b", c) = (1, 2, 3) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
84 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
85 SyntaxError: can't assign to literal |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
86 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
87 >>> [a, b, c + 1] = [1, 2, 3] |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
88 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
89 SyntaxError: can't assign to operator |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
90 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
91 >>> a if 1 else b = 1 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
92 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
93 SyntaxError: can't assign to conditional expression |
|
36418
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 From compiler_complex_args(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
96 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
97 >>> def f(None=1): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
98 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
99 Traceback (most recent call last): |
|
41969
9d02a4adf574
Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
100 SyntaxError: invalid syntax |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
101 |
|
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 From ast_for_arguments(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
104 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
105 >>> def f(x, y=1, z): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
106 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
107 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
108 SyntaxError: non-default argument follows default argument |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
109 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
110 >>> def f(x, None): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
111 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
112 Traceback (most recent call last): |
|
41969
9d02a4adf574
Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
113 SyntaxError: invalid syntax |
|
36418
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(*None): |
|
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): |
|
41969
9d02a4adf574
Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
118 SyntaxError: invalid syntax |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
119 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
120 >>> def f(**None): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
121 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
122 Traceback (most recent call last): |
|
41969
9d02a4adf574
Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
123 SyntaxError: invalid syntax |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
124 |
|
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 From ast_for_funcdef(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
127 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
128 >>> def None(x): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
129 ... pass |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
130 Traceback (most recent call last): |
|
41969
9d02a4adf574
Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
131 SyntaxError: invalid syntax |
|
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 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
134 From ast_for_call(): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
135 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
136 >>> def f(it, *varargs): |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
137 ... return list(it) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
138 >>> L = range(10) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
139 >>> f(x for x in L) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
140 [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
|
141 >>> f(x for x in L, 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
142 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
143 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
|
144 >>> f((x for x in L), 1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
145 [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
|
146 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
147 >>> 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
|
148 ... 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
|
149 ... 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
|
150 ... 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
|
151 ... 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
|
152 ... 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
|
153 ... 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
|
154 ... 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
|
155 ... 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
|
156 ... 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
|
157 ... 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
|
158 ... 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
|
159 ... 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
|
160 ... 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
|
161 ... 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
|
162 ... 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
|
163 ... 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
|
164 ... 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
|
165 ... 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
|
166 ... 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
|
167 ... 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
|
168 ... 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
|
169 ... 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
|
170 ... 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
|
171 ... 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
|
172 ... 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
|
173 ... i253, i254, i255) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
174 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
175 SyntaxError: more than 255 arguments |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
176 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
177 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
|
178 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
|
179 three. |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
180 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
181 >>> 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
|
182 ... 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
|
183 ... 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
|
184 ... 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
|
185 ... 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
|
186 ... 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
|
187 ... 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
|
188 ... 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
|
189 ... 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
|
190 ... 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
|
191 ... 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
|
192 ... 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
|
193 ... 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
|
194 ... 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
|
195 ... 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
|
196 ... 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
|
197 ... 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
|
198 ... 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
|
199 ... 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
|
200 ... 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
|
201 ... 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
|
202 ... 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
|
203 ... 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
|
204 ... 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
|
205 ... 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
|
206 ... (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
|
207 ... i252=1, i253=1, i254=1, i255=1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
208 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
209 SyntaxError: more than 255 arguments |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
210 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
211 >>> f(lambda x: x[0] = 3) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
212 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
213 SyntaxError: lambda cannot contain assignment |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
214 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
215 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
|
216 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
|
217 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
218 >>> f(x()=2) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
219 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
220 SyntaxError: keyword can't be an expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
221 >>> f(a or b=1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
222 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
223 SyntaxError: keyword can't be an expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
224 >>> f(x.y=1) |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
225 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
226 SyntaxError: keyword can't be an expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
227 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
228 |
|
54703
6370d71e3ca3
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48397
diff
changeset
|
229 More set_context(): |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
230 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
231 >>> (x for x in x) += 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
232 Traceback (most recent call last): |
|
54703
6370d71e3ca3
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48397
diff
changeset
|
233 SyntaxError: can't assign to generator expression |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
234 >>> None += 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
235 Traceback (most recent call last): |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
236 SyntaxError: assignment to keyword |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
237 >>> f() += 1 |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
238 Traceback (most recent call last): |
|
54703
6370d71e3ca3
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48397
diff
changeset
|
239 SyntaxError: can't assign to function call |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
240 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
241 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
242 Test continue in finally in weird combinations. |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
243 |
|
68585
bf94b6a73fc8
#11565: Fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64188
diff
changeset
|
244 continue in for loop under finally should be ok. |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
245 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
246 >>> def test(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
247 ... try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
248 ... pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
249 ... finally: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
250 ... for abc in range(10): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
251 ... continue |
|
40785
22760d53d4da
Fix a bunch of doctests with the -d option of refactor.py.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
252 ... print(abc) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
253 >>> test() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
254 9 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
255 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
256 Start simple, a continue in a finally should not be allowed. |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
257 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
258 >>> def test(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
259 ... for abc in range(10): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
260 ... try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
261 ... pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
262 ... finally: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
263 ... continue |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
264 Traceback (most recent call last): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
265 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
266 SyntaxError: 'continue' not supported inside 'finally' clause |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
267 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
268 This is essentially a continue in a finally which should not be allowed. |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
269 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
270 >>> def test(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
271 ... for abc in range(10): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
272 ... try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
273 ... pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
274 ... finally: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
275 ... try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
276 ... continue |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
277 ... except: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
278 ... pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
279 Traceback (most recent call last): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
280 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
281 SyntaxError: 'continue' not supported inside 'finally' clause |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
282 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
283 >>> def foo(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
284 ... try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
285 ... pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
286 ... finally: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
287 ... continue |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
288 Traceback (most recent call last): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
289 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
290 SyntaxError: 'continue' not supported inside 'finally' clause |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
291 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
292 >>> def foo(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
293 ... for a in (): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
294 ... try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
295 ... pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
296 ... finally: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
297 ... continue |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
298 Traceback (most recent call last): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
299 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
300 SyntaxError: 'continue' not supported inside 'finally' clause |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
301 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
302 >>> def foo(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
303 ... for a in (): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
304 ... try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
305 ... pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
306 ... finally: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
307 ... try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
308 ... continue |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
309 ... finally: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
310 ... pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
311 Traceback (most recent call last): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
312 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
313 SyntaxError: 'continue' not supported inside 'finally' clause |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
314 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
315 >>> def foo(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
316 ... for a in (): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
317 ... try: pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
318 ... finally: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
319 ... try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
320 ... pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
321 ... except: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
322 ... continue |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
323 Traceback (most recent call last): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
324 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
325 SyntaxError: 'continue' not supported inside 'finally' clause |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
326 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
327 There is one test for a break that is not in a loop. The compiler |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
328 uses a single data structure to keep track of try-finally and loops, |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
329 so we need to be sure that a break is actually inside a loop. If it |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
330 isn't, there should be a syntax error. |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
331 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
332 >>> try: |
|
40785
22760d53d4da
Fix a bunch of doctests with the -d option of refactor.py.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
333 ... print(1) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
334 ... break |
|
40785
22760d53d4da
Fix a bunch of doctests with the -d option of refactor.py.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
335 ... print(2) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
336 ... finally: |
|
40785
22760d53d4da
Fix a bunch of doctests with the -d option of refactor.py.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
337 ... print(3) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
338 Traceback (most recent call last): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
339 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
340 SyntaxError: 'break' outside loop |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
341 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
342 This should probably raise a better error than a SystemError (or none at all). |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
343 In 2.5 there was a missing exception and an assert was triggered in a debug |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
344 build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
345 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
346 >>> while 1: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
347 ... while 2: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
348 ... while 3: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
349 ... while 4: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
350 ... while 5: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
351 ... while 6: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
352 ... while 8: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
353 ... while 9: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
354 ... while 10: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
355 ... while 11: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
356 ... while 12: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
357 ... while 13: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
358 ... while 14: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
359 ... while 15: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
360 ... while 16: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
361 ... while 17: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
362 ... while 18: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
363 ... while 19: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
364 ... while 20: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
365 ... while 21: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
366 ... while 22: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
367 ... break |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
368 Traceback (most recent call last): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
369 ... |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
370 SystemError: too many statically nested blocks |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39674
diff
changeset
|
371 |
|
40965
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
372 Misuse of the nonlocal statement can lead to a few unique syntax errors. |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
373 |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
374 >>> def f(x): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
375 ... nonlocal x |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
376 Traceback (most recent call last): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
377 ... |
|
41464
060c79f6d919
Hide list comp variables and support set comprehensions
Nick Coghlan <ncoghlan@gmail.com>
parents:
40965
diff
changeset
|
378 SyntaxError: name 'x' is parameter and nonlocal |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
379 |
|
40965
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
380 >>> def f(): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
381 ... global x |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
382 ... nonlocal x |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
383 Traceback (most recent call last): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
384 ... |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
385 SyntaxError: name 'x' is nonlocal and global |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
386 |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
387 >>> def f(): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
388 ... nonlocal x |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
389 Traceback (most recent call last): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
390 ... |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
391 SyntaxError: no binding for nonlocal 'x' found |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
392 |
|
41508
55d761acdcbc
Don't crash when nonlocal is used at module level (fixes SF#1705365)
Nick Coghlan <ncoghlan@gmail.com>
parents:
41464
diff
changeset
|
393 From SF bug #1705365 |
|
55d761acdcbc
Don't crash when nonlocal is used at module level (fixes SF#1705365)
Nick Coghlan <ncoghlan@gmail.com>
parents:
41464
diff
changeset
|
394 >>> nonlocal x |
|
55d761acdcbc
Don't crash when nonlocal is used at module level (fixes SF#1705365)
Nick Coghlan <ncoghlan@gmail.com>
parents:
41464
diff
changeset
|
395 Traceback (most recent call last): |
|
55d761acdcbc
Don't crash when nonlocal is used at module level (fixes SF#1705365)
Nick Coghlan <ncoghlan@gmail.com>
parents:
41464
diff
changeset
|
396 ... |
|
55d761acdcbc
Don't crash when nonlocal is used at module level (fixes SF#1705365)
Nick Coghlan <ncoghlan@gmail.com>
parents:
41464
diff
changeset
|
397 SyntaxError: nonlocal declaration not allowed at module level |
|
55d761acdcbc
Don't crash when nonlocal is used at module level (fixes SF#1705365)
Nick Coghlan <ncoghlan@gmail.com>
parents:
41464
diff
changeset
|
398 |
|
40965
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
399 TODO(jhylton): Figure out how to test SyntaxWarning with doctest. |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
400 |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
401 ## >>> def f(x): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
402 ## ... def f(): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
403 ## ... print(x) |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
404 ## ... nonlocal x |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
405 ## Traceback (most recent call last): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
406 ## ... |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
407 ## SyntaxWarning: name 'x' is assigned to before nonlocal declaration |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
408 |
|
40965
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
409 ## >>> def f(): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
410 ## ... x = 1 |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
411 ## ... nonlocal x |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
412 ## Traceback (most recent call last): |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
413 ## ... |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
414 ## SyntaxWarning: name 'x' is assigned to before nonlocal declaration |
|
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
415 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
416 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
417 This tests assignment-context; there was a bug in Python 2.5 where compiling |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
418 a complex 'if' (one with 'elif') would fail to notice an invalid suite, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
419 leading to spurious errors. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
420 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
421 >>> if 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
422 ... x() = 1 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
423 ... elif 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
424 ... pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
425 Traceback (most recent call last): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
426 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
427 SyntaxError: can't assign to function call |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
428 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
429 >>> if 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
430 ... pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
431 ... elif 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
432 ... x() = 1 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
433 Traceback (most recent call last): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
434 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
435 SyntaxError: can't assign to function call |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
436 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
437 >>> if 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
438 ... x() = 1 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
439 ... elif 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
440 ... pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
441 ... else: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
442 ... pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
443 Traceback (most recent call last): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
444 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
445 SyntaxError: can't assign to function call |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
446 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
447 >>> if 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
448 ... pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
449 ... elif 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
450 ... x() = 1 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
451 ... else: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
452 ... pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
453 Traceback (most recent call last): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
454 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
455 SyntaxError: can't assign to function call |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
456 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
457 >>> if 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
458 ... pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
459 ... elif 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
460 ... pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
461 ... else: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
462 ... x() = 1 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
463 Traceback (most recent call last): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41508
diff
changeset
|
464 ... |
|
42455
dd74e020a132
Merged revisions 56492-56752 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41969
diff
changeset
|
465 SyntaxError: can't assign to function call |
|
40965
30e5cb3a55ac
Provisional implementation of PEP 3104.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
40788
diff
changeset
|
466 |
|
43102
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
467 Make sure that the old "raise X, Y[, Z]" form is gone: |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
468 >>> raise X, Y |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
469 Traceback (most recent call last): |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
470 ... |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
471 SyntaxError: invalid syntax |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
472 >>> raise X, Y, Z |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
473 Traceback (most recent call last): |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
474 ... |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
475 SyntaxError: invalid syntax |
|
981ecc526703
Issue #1066: implement PEP 3109, 2/3 of PEP 3134.
Collin Winter <collinw@gmail.com>
parents:
42455
diff
changeset
|
476 |
|
48397
42309437f1ca
Merged revisions 64622 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
477 |
|
42309437f1ca
Merged revisions 64622 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
478 >>> f(a=23, a=234) |
|
42309437f1ca
Merged revisions 64622 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
479 Traceback (most recent call last): |
|
42309437f1ca
Merged revisions 64622 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
480 ... |
|
42309437f1ca
Merged revisions 64622 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
481 SyntaxError: keyword argument repeated |
|
42309437f1ca
Merged revisions 64622 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
482 |
|
54918
0704f15b4682
Merged revisions 73376,73393,73398,73400,73404-73405,73409,73419-73421,73432,73457,73460,73485-73486,73488-73489,73501-73502,73513-73514 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54703
diff
changeset
|
483 >>> del () |
|
0704f15b4682
Merged revisions 73376,73393,73398,73400,73404-73405,73409,73419-73421,73432,73457,73460,73485-73486,73488-73489,73501-73502,73513-73514 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54703
diff
changeset
|
484 Traceback (most recent call last): |
|
0704f15b4682
Merged revisions 73376,73393,73398,73400,73404-73405,73409,73419-73421,73432,73457,73460,73485-73486,73488-73489,73501-73502,73513-73514 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54703
diff
changeset
|
485 SyntaxError: can't delete () |
|
0704f15b4682
Merged revisions 73376,73393,73398,73400,73404-73405,73409,73419-73421,73432,73457,73460,73485-73486,73488-73489,73501-73502,73513-73514 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54703
diff
changeset
|
486 |
|
62470
61fc84bc4b14
Merged revisions 82189 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54918
diff
changeset
|
487 >>> {1, 2, 3} = 42 |
|
61fc84bc4b14
Merged revisions 82189 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54918
diff
changeset
|
488 Traceback (most recent call last): |
|
61fc84bc4b14
Merged revisions 82189 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54918
diff
changeset
|
489 SyntaxError: can't assign to literal |
|
61fc84bc4b14
Merged revisions 82189 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
54918
diff
changeset
|
490 |
|
64185
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
491 Corner-cases that used to fail to raise the correct error: |
|
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
492 |
|
64184
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
493 >>> def f(*, x=lambda __debug__:0): pass |
|
64185
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
494 Traceback (most recent call last): |
|
64184
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
495 SyntaxError: assignment to keyword |
|
64185
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
496 |
|
64184
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
497 >>> def f(*args:(lambda __debug__:0)): pass |
|
64185
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
498 Traceback (most recent call last): |
|
64184
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
499 SyntaxError: assignment to keyword |
|
64185
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
500 |
|
64184
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
501 >>> def f(**kwargs:(lambda __debug__:0)): pass |
|
64185
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
502 Traceback (most recent call last): |
|
64184
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
503 SyntaxError: assignment to keyword |
|
64185
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
504 |
|
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
505 >>> with (lambda *:0): pass |
|
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
506 Traceback (most recent call last): |
|
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
507 SyntaxError: named arguments must follow bare * |
|
38ceeae0d1f0
Merged revisions 84214 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54703
diff
changeset
|
508 |
|
64184
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
509 Corner-cases that used to crash: |
|
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
510 |
|
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
511 >>> def f(**__debug__): pass |
|
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
512 Traceback (most recent call last): |
|
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
513 SyntaxError: assignment to keyword |
|
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
514 |
|
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
515 >>> def f(*xx, __debug__): pass |
|
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
516 Traceback (most recent call last): |
|
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
517 SyntaxError: assignment to keyword |
|
c18eeb969102
Add tests for r84209 (crashes in the Ast builder)
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
62470
diff
changeset
|
518 |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
519 """ |
|
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
520 |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
521 import re |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
522 import unittest |
|
29870
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
523 import warnings |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
524 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
43102
diff
changeset
|
525 from test import support |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
526 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
527 class SyntaxTestCase(unittest.TestCase): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
528 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
529 def _check_error(self, code, errtext, |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
530 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
|
531 """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
|
532 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
533 errtest is a regular expression that must be present in the |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
534 test of the exception raised. If subclass is specified it |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
535 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
|
536 """ |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
537 try: |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
538 compile(code, filename, mode) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
539 except SyntaxError as err: |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
540 if subclass and not isinstance(err, subclass): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
541 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
|
542 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
|
543 if mo is None: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
29870
diff
changeset
|
544 self.fail("SyntaxError did not contain '%r'" % (errtext,)) |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
545 else: |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
546 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
|
547 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
548 def test_assign_call(self): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
549 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
|
550 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
551 def test_assign_del(self): |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
552 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
|
553 |
|
29870
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
554 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
|
555 # 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
|
556 # shouldn't be clobbered by a SyntaxWarning issued for a later one. |
|
64616
16a42d5f2209
The "if 1": trick seems cleaner that the one with regular expressions.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64184
diff
changeset
|
557 source = """if 1: |
|
16a42d5f2209
The "if 1": trick seems cleaner that the one with regular expressions.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64184
diff
changeset
|
558 def error(a): |
|
16a42d5f2209
The "if 1": trick seems cleaner that the one with regular expressions.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64184
diff
changeset
|
559 global a # SyntaxError |
|
16a42d5f2209
The "if 1": trick seems cleaner that the one with regular expressions.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64184
diff
changeset
|
560 def warning(): |
|
16a42d5f2209
The "if 1": trick seems cleaner that the one with regular expressions.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64184
diff
changeset
|
561 b = 1 |
|
16a42d5f2209
The "if 1": trick seems cleaner that the one with regular expressions.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64184
diff
changeset
|
562 global b # SyntaxWarning |
|
16a42d5f2209
The "if 1": trick seems cleaner that the one with regular expressions.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
64184
diff
changeset
|
563 """ |
|
29870
030227de8051
SF patch 763201: handling of SyntaxErrors in symbol table build
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24364
diff
changeset
|
564 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
|
565 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
|
566 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
|
567 |
|
35959
fca7337710fd
Improve test coverage. Hope the test_file changes work the same on windows.
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
568 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
|
569 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
|
570 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
571 def test_unexpected_indent(self): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
572 self._check_error("foo()\n bar()\n", "unexpected indent", |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
573 subclass=IndentationError) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
574 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
575 def test_no_indent(self): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
576 self._check_error("if 1:\nfoo()", "expected an indented block", |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
577 subclass=IndentationError) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
578 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
579 def test_bad_outdent(self): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
580 self._check_error("if 1:\n foo()\n bar()", |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
581 "unindent does not match .* level", |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
582 subclass=IndentationError) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
583 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
584 def test_kwargs_last(self): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
585 self._check_error("int(base=10, '2')", "non-keyword arg") |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36418
diff
changeset
|
586 |
|
23589
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
587 def test_main(): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
43102
diff
changeset
|
588 support.run_unittest(SyntaxTestCase) |
|
36418
a625e8876407
Improved handling of syntax errors.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35959
diff
changeset
|
589 from test import test_syntax |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
43102
diff
changeset
|
590 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
|
591 |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
592 if __name__ == "__main__": |
|
b0658feef939
Fix SF bug [ 561825 ] Confusing error for "del f()"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
593 test_main() |
