coconut-develop 3.2.0.post0.dev15__py2.py3-none-any.whl → 3.2.0.post0.dev17__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- __coconut__/__init__.pyi +2 -2
- coconut/_pyparsing.py +2 -2
- coconut/api.py +3 -3
- coconut/api.pyi +7 -7
- coconut/command/command.py +10 -5
- coconut/compiler/compiler.py +50 -36
- coconut/compiler/grammar.py +32 -11
- coconut/constants.py +4 -1
- coconut/icoconut/root.py +38 -7
- coconut/root.py +1 -1
- coconut/tests/main_test.py +19 -0
- coconut/tests/src/cocotest/agnostic/primary_2.coco +1 -1
- coconut/tests/src/cocotest/agnostic/specific.coco +1 -1
- coconut/tests/src/extras.coco +158 -136
- {coconut_develop-3.2.0.post0.dev15.dist-info → coconut_develop-3.2.0.post0.dev17.dist-info}/METADATA +166 -134
- {coconut_develop-3.2.0.post0.dev15.dist-info → coconut_develop-3.2.0.post0.dev17.dist-info}/RECORD +21 -21
- {coconut_develop-3.2.0.post0.dev15.dist-info → coconut_develop-3.2.0.post0.dev17.dist-info}/WHEEL +1 -1
- {coconut_develop-3.2.0.post0.dev15.dist-info → coconut_develop-3.2.0.post0.dev17.dist-info}/entry_points.txt +4 -4
- {coconut_develop-3.2.0.post0.dev15.data → coconut_develop-3.2.0.post0.dev17.data}/data/share/jupyter/kernels/coconut/kernel.json +0 -0
- {coconut_develop-3.2.0.post0.dev15.dist-info → coconut_develop-3.2.0.post0.dev17.dist-info}/licenses/LICENSE.txt +0 -0
- {coconut_develop-3.2.0.post0.dev15.dist-info → coconut_develop-3.2.0.post0.dev17.dist-info}/top_level.txt +0 -0
coconut/tests/src/extras.coco
CHANGED
|
@@ -33,6 +33,9 @@ from coconut.convenience import (
|
|
|
33
33
|
)
|
|
34
34
|
|
|
35
35
|
|
|
36
|
+
parse_with_state = parse$(keep_internal_state=True)
|
|
37
|
+
|
|
38
|
+
|
|
36
39
|
def assert_raises(c, Exc, not_Exc=None, err_has=None) -> None:
|
|
37
40
|
"""Test whether callable c raises an exception of type Exc."""
|
|
38
41
|
if not_Exc is None and Exc is CoconutSyntaxError:
|
|
@@ -98,87 +101,87 @@ def test_setup_none() -> bool:
|
|
|
98
101
|
coconut_exec("def f(x) = x", exec_vars)
|
|
99
102
|
assert exec_vars["f"](10) == 10
|
|
100
103
|
|
|
101
|
-
assert
|
|
102
|
-
assert
|
|
103
|
-
assert
|
|
104
|
-
assert
|
|
105
|
-
assert
|
|
106
|
-
assert
|
|
107
|
-
assert
|
|
108
|
-
assert "_coconut" not in
|
|
109
|
-
assert "_coconut" not in
|
|
110
|
-
assert
|
|
111
|
-
assert
|
|
112
|
-
assert
|
|
113
|
-
assert
|
|
114
|
-
assert
|
|
115
|
-
assert
|
|
116
|
-
assert
|
|
117
|
-
assert "==" not in
|
|
118
|
-
assert
|
|
119
|
-
assert "Ellipsis" not in
|
|
120
|
-
assert
|
|
104
|
+
assert parse_with_state("abc") == parse_with_state("abc", "sys")
|
|
105
|
+
assert parse_with_state("abc", "file")
|
|
106
|
+
assert parse_with_state("abc", "package")
|
|
107
|
+
assert parse_with_state("abc", "block") == "abc\n" == parse_with_state("abc", "single")
|
|
108
|
+
assert parse_with_state("abc", "eval") == "abc" == parse_with_state(" abc", "eval")
|
|
109
|
+
assert parse_with_state("abc", "lenient") == "abc" == parse_with_state(" abc", "lenient")
|
|
110
|
+
assert parse_with_state("x |> map$(f)", "lenient") == "(map)(f, x)"
|
|
111
|
+
assert "_coconut" not in parse_with_state("a |> .b |> .m() |> f$(x) |> .[0]", "block")
|
|
112
|
+
assert "_coconut" not in parse_with_state("a |>= f$(x)", "block")
|
|
113
|
+
assert parse_with_state("abc # derp", "lenient") == "abc # derp"
|
|
114
|
+
assert parse_with_state("def f(x):\n \t pass")
|
|
115
|
+
assert parse_with_state("lambda x: x")
|
|
116
|
+
assert parse_with_state("u''")
|
|
117
|
+
assert parse_with_state("def f(x):\\\n pass")
|
|
118
|
+
assert parse_with_state("abc ")
|
|
119
|
+
assert parse_with_state("abc # derp", "lenient") == "abc # derp"
|
|
120
|
+
assert "==" not in parse_with_state("None = None")
|
|
121
|
+
assert parse_with_state("(1\f+\f2)", "lenient") == "(1 + 2)" == parse_with_state("(1\f+\f2)", "eval")
|
|
122
|
+
assert "Ellipsis" not in parse_with_state("x: ... = 1")
|
|
123
|
+
assert parse_with_state("linebreaks = '\x0b\x0c\x1c\x1d\x1e'")
|
|
121
124
|
|
|
122
125
|
# things that don't parse correctly without the computation graph
|
|
123
126
|
if USE_COMPUTATION_GRAPH:
|
|
124
|
-
exec(
|
|
125
|
-
|
|
126
|
-
assert_raises(->
|
|
127
|
-
assert_raises(->
|
|
128
|
-
assert_raises(->
|
|
129
|
-
|
|
130
|
-
assert_raises(->
|
|
131
|
-
assert_raises(->
|
|
132
|
-
assert_raises(->
|
|
133
|
-
assert_raises(->
|
|
134
|
-
assert_raises(->
|
|
135
|
-
assert_raises(->
|
|
136
|
-
assert_raises(->
|
|
137
|
-
assert_raises(->
|
|
138
|
-
assert_raises(->
|
|
139
|
-
assert_raises(->
|
|
140
|
-
assert_raises(->
|
|
141
|
-
assert_raises(->
|
|
142
|
-
assert_raises(->
|
|
143
|
-
assert_raises(->
|
|
144
|
-
assert_raises(->
|
|
145
|
-
assert_raises(->
|
|
146
|
-
assert_raises(->
|
|
147
|
-
assert_raises(->
|
|
148
|
-
assert_raises(->
|
|
149
|
-
assert_raises(->
|
|
150
|
-
|
|
151
|
-
assert_raises(->
|
|
127
|
+
exec(parse_with_state("assert (1,2,3,4) == ([1, 2], [3, 4]) |*> def (x, y) -> *x, *y"), {})
|
|
128
|
+
|
|
129
|
+
assert_raises(-> parse_with_state("(a := b)"), CoconutTargetError)
|
|
130
|
+
assert_raises(-> parse_with_state("async def f() = 1"), CoconutTargetError)
|
|
131
|
+
assert_raises(-> parse_with_state("exec = 1"), CoconutTargetError)
|
|
132
|
+
|
|
133
|
+
assert_raises(-> parse_with_state(" abc", "file"), CoconutSyntaxError)
|
|
134
|
+
assert_raises(-> parse_with_state("'"), CoconutSyntaxError)
|
|
135
|
+
assert_raises(-> parse_with_state("("), CoconutSyntaxError)
|
|
136
|
+
assert_raises(-> parse_with_state("\\("), CoconutSyntaxError)
|
|
137
|
+
assert_raises(-> parse_with_state("if a:\n b\n c"), CoconutSyntaxError)
|
|
138
|
+
assert_raises(-> parse_with_state("_coconut"), CoconutSyntaxError)
|
|
139
|
+
assert_raises(-> parse_with_state("[; ;]"), CoconutSyntaxError)
|
|
140
|
+
assert_raises(-> parse_with_state("[; ;; ;]"), CoconutSyntaxError)
|
|
141
|
+
assert_raises(-> parse_with_state("[; ; ;;]"), CoconutSyntaxError)
|
|
142
|
+
assert_raises(-> parse_with_state("[[] ;;; ;; [] ;]"), CoconutSyntaxError)
|
|
143
|
+
assert_raises(-> parse_with_state("[; []]"), CoconutSyntaxError)
|
|
144
|
+
assert_raises(-> parse_with_state("f$()"), CoconutSyntaxError)
|
|
145
|
+
assert_raises(-> parse_with_state("f(**x, y)"), CoconutSyntaxError)
|
|
146
|
+
assert_raises(-> parse_with_state("def f(x) = return x"), CoconutSyntaxError)
|
|
147
|
+
assert_raises(-> parse_with_state("def f(x) =\n return x"), CoconutSyntaxError)
|
|
148
|
+
assert_raises(-> parse_with_state("10 20"), CoconutSyntaxError)
|
|
149
|
+
assert_raises(-> parse_with_state('x + "1" + (=="2") = "test"'), CoconutSyntaxError)
|
|
150
|
+
assert_raises(-> parse_with_state('(==x) + "1" + y = "test"'), CoconutSyntaxError)
|
|
151
|
+
assert_raises(-> parse_with_state(r'd"\n hello"'), CoconutSyntaxError)
|
|
152
|
+
assert_raises(-> parse_with_state('d""" hello"""'), CoconutSyntaxError)
|
|
153
|
+
|
|
154
|
+
assert_raises(-> parse_with_state("()[(())"), CoconutSyntaxError, err_has="""
|
|
152
155
|
unclosed open '[' (line 1)
|
|
153
156
|
()[(())
|
|
154
157
|
^
|
|
155
158
|
""".strip())
|
|
156
|
-
assert_raises(->
|
|
159
|
+
assert_raises(-> parse_with_state("{}(([])"), CoconutSyntaxError, err_has="""
|
|
157
160
|
unclosed open '(' (line 1)
|
|
158
161
|
{}(([])
|
|
159
162
|
^
|
|
160
163
|
""".strip())
|
|
161
|
-
assert_raises(->
|
|
164
|
+
assert_raises(-> parse_with_state("{[]{}}}()"), CoconutSyntaxError, err_has="""
|
|
162
165
|
unmatched close '}' (line 1)
|
|
163
166
|
{[]{}}}()
|
|
164
167
|
^
|
|
165
168
|
""".strip())
|
|
166
|
-
assert_raises(->
|
|
169
|
+
assert_raises(-> parse_with_state("[([){[}"), CoconutSyntaxError, err_has="""
|
|
167
170
|
mismatched open '[' and close ')' (line 1)
|
|
168
171
|
[([){[}
|
|
169
172
|
~^
|
|
170
173
|
""".strip())
|
|
171
|
-
assert_raises(->
|
|
174
|
+
assert_raises(-> parse_with_state("[())]"), CoconutSyntaxError, err_has=r"""
|
|
172
175
|
mismatched open '[' and close ')' (line 1)
|
|
173
176
|
[())]
|
|
174
177
|
\~~^
|
|
175
178
|
""".strip())
|
|
176
|
-
assert_raises(->
|
|
179
|
+
assert_raises(-> parse_with_state("[[\n])"), CoconutSyntaxError, err_has="""
|
|
177
180
|
mismatched open '[' and close ')' (line 1)
|
|
178
181
|
])
|
|
179
182
|
^
|
|
180
183
|
""".strip())
|
|
181
|
-
assert_raises(->
|
|
184
|
+
assert_raises(-> parse_with_state(d"""
|
|
182
185
|
a = 1
|
|
183
186
|
b = f"{1+}"
|
|
184
187
|
c = 3
|
|
@@ -188,30 +191,30 @@ parsing failed for format string expression: 1+ (line 2)
|
|
|
188
191
|
^
|
|
189
192
|
""".strip())
|
|
190
193
|
|
|
191
|
-
assert_raises(->
|
|
194
|
+
assert_raises(-> parse_with_state(d"""
|
|
192
195
|
case def f[T]:
|
|
193
196
|
case(x) = x
|
|
194
197
|
"""), CoconutSyntaxError)
|
|
195
|
-
assert_raises(->
|
|
198
|
+
assert_raises(-> parse_with_state(d"""
|
|
196
199
|
case def f[T]:
|
|
197
200
|
type(x: T) -> T
|
|
198
201
|
"""), CoconutSyntaxError)
|
|
199
202
|
|
|
200
|
-
assert_raises(->
|
|
201
|
-
assert_raises(->
|
|
202
|
-
assert_raises(->
|
|
203
|
-
assert_raises(->
|
|
204
|
-
assert_raises(->
|
|
205
|
-
assert_raises(->
|
|
206
|
-
assert_raises(->
|
|
207
|
-
assert_raises(->
|
|
208
|
-
assert_raises(->
|
|
209
|
-
assert_raises(->
|
|
203
|
+
assert_raises(-> parse_with_state("(|*?>)"), CoconutSyntaxError, err_has="'|?*>'")
|
|
204
|
+
assert_raises(-> parse_with_state("(|**?>)"), CoconutSyntaxError, err_has="'|?**>'")
|
|
205
|
+
assert_raises(-> parse_with_state("(<?*|)"), CoconutSyntaxError, err_has="'<*?|'")
|
|
206
|
+
assert_raises(-> parse_with_state("(<?**|)"), CoconutSyntaxError, err_has="'<**?|'")
|
|
207
|
+
assert_raises(-> parse_with_state("(..*?>)"), CoconutSyntaxError, err_has="'..?*>'")
|
|
208
|
+
assert_raises(-> parse_with_state("(..**?>)"), CoconutSyntaxError, err_has="'..?**>'")
|
|
209
|
+
assert_raises(-> parse_with_state("(<?*..)"), CoconutSyntaxError, err_has="'<*?..'")
|
|
210
|
+
assert_raises(-> parse_with_state("(<?**..)"), CoconutSyntaxError, err_has="'<**?..'")
|
|
211
|
+
assert_raises(-> parse_with_state("(.+1) .. x -> x * 2"), CoconutSyntaxError, err_has="<..")
|
|
212
|
+
assert_raises(-> parse_with_state('f"Black holes {*all_black_holes} and revelations"'), CoconutSyntaxError, err_has="format string")
|
|
210
213
|
assert_raises(-> parse("operator ++\noperator ++"), CoconutSyntaxError, err_has="custom operator already declared")
|
|
211
|
-
assert_raises(->
|
|
214
|
+
assert_raises(-> parse_with_state("type HasIn = (in)"), CoconutSyntaxError, err_has="not supported")
|
|
212
215
|
|
|
213
216
|
assert_raises(
|
|
214
|
-
->
|
|
217
|
+
-> parse_with_state("type abc[T,T] = T | T"),
|
|
215
218
|
CoconutSyntaxError,
|
|
216
219
|
err_has=r"""
|
|
217
220
|
cannot reassign type variable 'T' (use explicit '\T' syntax if intended) (line 1)
|
|
@@ -220,24 +223,24 @@ cannot reassign type variable 'T' (use explicit '\T' syntax if intended) (line 1
|
|
|
220
223
|
""".strip(),
|
|
221
224
|
)
|
|
222
225
|
|
|
223
|
-
assert_raises(->
|
|
224
|
-
assert_raises(->
|
|
225
|
-
assert_raises(->
|
|
226
|
+
assert_raises(-> parse_with_state("$"), CoconutParseError)
|
|
227
|
+
assert_raises(-> parse_with_state("@"), CoconutParseError)
|
|
228
|
+
assert_raises(-> parse_with_state("range(1,10) |> reduce$(*, initializer = 1000) |> print"), CoconutParseError, err_has=(
|
|
226
229
|
"\n \\~~^",
|
|
227
230
|
"\n \\~~~~~~~~~~~~~~~~~~~~~~~^",
|
|
228
231
|
) + (
|
|
229
232
|
("\n \\~~~~~~~~~~~~^",)
|
|
230
233
|
if PYPY else ()
|
|
231
234
|
))
|
|
232
|
-
assert_raises(->
|
|
235
|
+
assert_raises(-> parse_with_state("a := b"), CoconutParseError, err_has=(
|
|
233
236
|
"\n ^",
|
|
234
237
|
"\n \\~^",
|
|
235
238
|
))
|
|
236
|
-
assert_raises(->
|
|
239
|
+
assert_raises(-> parse_with_state("1 + return"), CoconutParseError, err_has=(
|
|
237
240
|
"\n \\~~^",
|
|
238
241
|
"\n \\~~~~^",
|
|
239
242
|
))
|
|
240
|
-
assert_raises(->
|
|
243
|
+
assert_raises(-> parse_with_state(d"""
|
|
241
244
|
def f() =
|
|
242
245
|
assert 1
|
|
243
246
|
assert 2
|
|
@@ -252,41 +255,41 @@ cannot reassign type variable 'T' (use explicit '\T' syntax if intended) (line 1
|
|
|
252
255
|
~^
|
|
253
256
|
""".strip(),
|
|
254
257
|
))
|
|
255
|
-
assert_raises(->
|
|
258
|
+
assert_raises(-> parse_with_state('b"abc" "def"'), CoconutParseError, err_has=(
|
|
256
259
|
"\n ^",
|
|
257
260
|
"\n \\~~~~~~^",
|
|
258
261
|
))
|
|
259
|
-
assert_raises(->
|
|
262
|
+
assert_raises(-> parse_with_state('"abc" b"def"'), CoconutParseError, err_has=(
|
|
260
263
|
"\n ^",
|
|
261
264
|
"\n \\~~~~~^",
|
|
262
265
|
))
|
|
263
|
-
assert_raises(->
|
|
266
|
+
assert_raises(-> parse_with_state("A. ."), CoconutParseError, err_has=(
|
|
264
267
|
"\n \\~^",
|
|
265
268
|
"\n \\~~^",
|
|
266
269
|
))
|
|
267
|
-
assert_raises(->
|
|
270
|
+
assert_raises(-> parse_with_state("f([] {})"), CoconutParseError, err_has=(
|
|
268
271
|
"\n \\~~~^",
|
|
269
272
|
"\n \\~~~~^",
|
|
270
273
|
))
|
|
271
|
-
assert_raises(->
|
|
274
|
+
assert_raises(-> parse_with_state("0xfgf"), CoconutParseError, err_has=(
|
|
272
275
|
"\n ^",
|
|
273
276
|
"\n \\~^",
|
|
274
277
|
"\n \\~~^",
|
|
275
278
|
))
|
|
276
|
-
assert_raises(->
|
|
279
|
+
assert_raises(-> parse_with_state("(. if 1)"), CoconutParseError, err_has=(
|
|
277
280
|
"\n ^",
|
|
278
281
|
"\n \\~~^",
|
|
279
282
|
))
|
|
280
283
|
|
|
281
|
-
assert_raises(->
|
|
284
|
+
assert_raises(-> parse_with_state('''f"""{
|
|
282
285
|
}"""'''), CoconutSyntaxError, err_has="parsing failed for format string expression")
|
|
283
|
-
assert_raises(->
|
|
284
|
-
assert_raises(->
|
|
286
|
+
assert_raises(-> parse_with_state("if a = b: pass"), CoconutParseError, err_has="misplaced assignment")
|
|
287
|
+
assert_raises(-> parse_with_state("while a == b"), CoconutParseError, err_has="misplaced newline")
|
|
285
288
|
# implicit coefficient followed by subscript in list should be a parse error, not internal error
|
|
286
|
-
assert_raises(->
|
|
289
|
+
assert_raises(-> parse_with_state("[(0)foo[0] for _ in [0]]"), CoconutParseError)
|
|
287
290
|
|
|
288
291
|
try:
|
|
289
|
-
|
|
292
|
+
parse_with_state(d"""
|
|
290
293
|
def gam_eps_rate(bitarr) = (
|
|
291
294
|
bitarr
|
|
292
295
|
|*> zip
|
|
@@ -315,7 +318,7 @@ cannot reassign type variable 'T' (use explicit '\T' syntax if intended) (line 1
|
|
|
315
318
|
assert False
|
|
316
319
|
|
|
317
320
|
try:
|
|
318
|
-
|
|
321
|
+
parse_with_state(d"""
|
|
319
322
|
def f(x=1, y) = x, y
|
|
320
323
|
|
|
321
324
|
class A
|
|
@@ -329,27 +332,31 @@ cannot reassign type variable 'T' (use explicit '\T' syntax if intended) (line 1
|
|
|
329
332
|
else:
|
|
330
333
|
assert False
|
|
331
334
|
|
|
332
|
-
assert
|
|
333
|
-
assert "data ABC" not in
|
|
334
|
-
|
|
335
|
-
assert
|
|
336
|
-
assert "
|
|
337
|
-
assert
|
|
338
|
-
assert "builder" in
|
|
339
|
-
assert
|
|
340
|
-
assert
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
assert_raises(->
|
|
347
|
-
assert_raises(->
|
|
348
|
-
assert_raises(->
|
|
349
|
-
assert_raises(->
|
|
350
|
-
assert_raises(->
|
|
351
|
-
assert_raises(->
|
|
352
|
-
assert_raises(->
|
|
335
|
+
assert parse_with_state("def f(x):\n ${var}", "xonsh") == "def f(x):\n ${var}\n"
|
|
336
|
+
assert "data ABC" not in parse_with_state("data ABC:\n ${var}", "xonsh")
|
|
337
|
+
# backslash continuations in shell commands (#906)
|
|
338
|
+
assert parse_with_state("echo a \\\n b # NOQA", "xonsh").startswith("echo a b"), parse_with_state("echo a \\\n b # NOQA", "xonsh")
|
|
339
|
+
assert parse_with_state("$(ls \\\n -la)", "xonsh").startswith("$(ls -la)"), parse_with_state("$(ls \\\n -la)", "xonsh")
|
|
340
|
+
assert parse_with_state("x = 1 + \\\n 2", "xonsh").startswith("x = 1 + 2"), parse_with_state("x = 1 + \\\n 2", "xonsh")
|
|
341
|
+
assert "builder" not in parse_with_state("def x -> x", "lenient")
|
|
342
|
+
assert parse_with_state("def x -> x", "lenient").count("def") == 1
|
|
343
|
+
assert "builder" in parse_with_state("x -> def y -> (x, y)", "lenient")
|
|
344
|
+
assert parse_with_state("x -> def y -> (x, y)", "lenient").count("def") == 2
|
|
345
|
+
assert "builder" in parse_with_state("[def x -> (x, y) for y in range(10)]", "lenient")
|
|
346
|
+
assert parse_with_state("[def x -> (x, y) for y in range(10)]", "lenient").count("def") == 2
|
|
347
|
+
assert parse_with_state("123 # derp", "lenient") == "123 # derp"
|
|
348
|
+
|
|
349
|
+
assert_raises(-> parse_with_state("final x = 1\nx = 2"), CoconutSyntaxError, err_has="final")
|
|
350
|
+
assert_raises(-> parse_with_state("final x = 1\nx += 1"), CoconutSyntaxError, err_has="final")
|
|
351
|
+
assert_raises(-> parse_with_state("final x = 1\ndel x"), CoconutSyntaxError, err_has="final")
|
|
352
|
+
assert_raises(-> parse_with_state("final x = 1\nfor x in [1]: pass"), CoconutSyntaxError, err_has="final")
|
|
353
|
+
assert_raises(-> parse_with_state("final x = 1\nwith foo() as x: pass"), CoconutSyntaxError, err_has="final")
|
|
354
|
+
assert_raises(-> parse_with_state("final e = 1\ntry: pass\nexcept E as e: pass"), CoconutSyntaxError, err_has="final")
|
|
355
|
+
assert_raises(-> parse_with_state("final os = 1\nimport os"), CoconutSyntaxError, err_has="final")
|
|
356
|
+
assert_raises(-> parse_with_state("final path = 1\nfrom os import path"), CoconutSyntaxError, err_has="final")
|
|
357
|
+
assert_raises(-> parse_with_state("def f(final x): x = 2"), CoconutSyntaxError, err_has="final")
|
|
358
|
+
assert_raises(-> parse_with_state("final x = 1\nmatch y:\n case x: pass"), CoconutSyntaxError, err_has="final")
|
|
359
|
+
assert_raises(-> parse_with_state("final x = 1\nfinal x = 2"), CoconutSyntaxError, err_has="final")
|
|
353
360
|
|
|
354
361
|
return True
|
|
355
362
|
|
|
@@ -364,12 +371,12 @@ def test_api() -> bool:
|
|
|
364
371
|
assert_raises(-> cmd("-n . ."), SystemExit)
|
|
365
372
|
|
|
366
373
|
setup()
|
|
367
|
-
assert
|
|
374
|
+
assert parse_with_state("abc", "lenient") == "abc #1 (line in Coconut source)"
|
|
368
375
|
setup(line_numbers=False, keep_lines=True)
|
|
369
|
-
assert
|
|
376
|
+
assert parse_with_state("abc", "lenient") == "abc # abc"
|
|
370
377
|
setup(keep_lines=True)
|
|
371
|
-
assert
|
|
372
|
-
assert "#6:" in
|
|
378
|
+
assert parse_with_state("abc", "lenient") == "abc #1: abc"
|
|
379
|
+
assert "#6:" in parse_with_state('''line 1
|
|
373
380
|
f"""{"""
|
|
374
381
|
"""}""" + """
|
|
375
382
|
""" + f"""{\'\'\'
|
|
@@ -377,24 +384,24 @@ f"""{"""
|
|
|
377
384
|
line 6''')
|
|
378
385
|
|
|
379
386
|
setup(line_numbers=False)
|
|
380
|
-
assert "Deprecated Coconut built-in 'prepattern' disabled by --strict compilation" not in
|
|
381
|
-
assert "Deprecated Coconut built-in 'datamaker' disabled by --strict compilation" not in
|
|
382
|
-
assert "Deprecated Coconut built-in 'of' disabled by --strict compilation" not in
|
|
387
|
+
assert "Deprecated Coconut built-in 'prepattern' disabled by --strict compilation" not in parse_with_state("\n", mode="file")
|
|
388
|
+
assert "Deprecated Coconut built-in 'datamaker' disabled by --strict compilation" not in parse_with_state("\n", mode="file")
|
|
389
|
+
assert "Deprecated Coconut built-in 'of' disabled by --strict compilation" not in parse_with_state("\n", mode="file")
|
|
383
390
|
|
|
384
391
|
setup(line_numbers=False, strict=True)
|
|
385
|
-
assert "Deprecated Coconut built-in 'prepattern' disabled by --strict compilation" in
|
|
386
|
-
assert "Deprecated Coconut built-in 'datamaker' disabled by --strict compilation" in
|
|
387
|
-
assert "Deprecated Coconut built-in 'of' disabled by --strict compilation" in
|
|
388
|
-
|
|
389
|
-
assert_raises(->
|
|
390
|
-
assert_raises(->
|
|
391
|
-
assert_raises(->
|
|
392
|
-
assert_raises(->
|
|
393
|
-
assert_raises(->
|
|
394
|
-
assert_raises(->
|
|
395
|
-
assert_raises(->
|
|
396
|
-
assert_raises(->
|
|
397
|
-
assert_raises(->
|
|
392
|
+
assert "Deprecated Coconut built-in 'prepattern' disabled by --strict compilation" in parse_with_state("\n", mode="file")
|
|
393
|
+
assert "Deprecated Coconut built-in 'datamaker' disabled by --strict compilation" in parse_with_state("\n", mode="file")
|
|
394
|
+
assert "Deprecated Coconut built-in 'of' disabled by --strict compilation" in parse_with_state("\n", mode="file")
|
|
395
|
+
|
|
396
|
+
assert_raises(-> parse_with_state("def f(x):\n \t pass"), CoconutStyleError)
|
|
397
|
+
assert_raises(-> parse_with_state("lambda x: x"), CoconutStyleError)
|
|
398
|
+
assert_raises(-> parse_with_state("u''"), CoconutStyleError)
|
|
399
|
+
assert_raises(-> parse_with_state("def f(x):\\\n pass"), CoconutStyleError)
|
|
400
|
+
assert_raises(-> parse_with_state("abc "), CoconutStyleError, err_has="\n ^")
|
|
401
|
+
assert_raises(-> parse_with_state("abc", "file"), CoconutStyleError)
|
|
402
|
+
assert_raises(-> parse_with_state("class derp(object)"), CoconutStyleError)
|
|
403
|
+
assert_raises(-> parse_with_state("def f(a.b) = True"), CoconutStyleError, err_has="\n ^")
|
|
404
|
+
assert_raises(-> parse_with_state("match def kwd_only_x_is_int_def_0(*, x is int = 0) = x"), CoconutStyleError, err_has=(
|
|
398
405
|
"\n ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|",
|
|
399
406
|
"\n ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/",
|
|
400
407
|
) + (
|
|
@@ -402,7 +409,7 @@ line 6''')
|
|
|
402
409
|
if PYPY else ()
|
|
403
410
|
))
|
|
404
411
|
try:
|
|
405
|
-
|
|
412
|
+
parse_with_state(d"""
|
|
406
413
|
try:
|
|
407
414
|
x is int is str = x
|
|
408
415
|
except MatchError:
|
|
@@ -413,13 +420,13 @@ line 6''')
|
|
|
413
420
|
except CoconutStyleError as err:
|
|
414
421
|
assert str(err).startswith("""found deprecated isinstance-checking 'x is int is str' pattern; rewrite to use class patterns (try 'int(x) and str(x)') or explicit isinstance-checking ('x `isinstance` int and x `isinstance` str' should always work) (remove --strict to downgrade to a warning) (line 2)
|
|
415
422
|
x is int is str = x"""), err
|
|
416
|
-
assert_raises(->
|
|
423
|
+
assert_raises(-> parse_with_state("""case x:
|
|
417
424
|
match x:
|
|
418
425
|
pass"""), CoconutStyleError, err_has="case x:")
|
|
419
|
-
assert_raises(->
|
|
420
|
-
assert_raises(->
|
|
421
|
-
assert_raises(->
|
|
422
|
-
assert_raises(->
|
|
426
|
+
assert_raises(-> parse_with_state("obj."), CoconutStyleError, err_has="getattr")
|
|
427
|
+
assert_raises(-> parse_with_state("def x -> pass, 1"), CoconutStyleError, err_has="statement lambda")
|
|
428
|
+
assert_raises(-> parse_with_state("abc = f'abc'"), CoconutStyleError, err_has="\n ^")
|
|
429
|
+
assert_raises(-> parse_with_state('f"{f"{f"infinite"}"}"'), CoconutStyleError, err_has="f-string with no expressions")
|
|
423
430
|
try:
|
|
424
431
|
parse(d"""
|
|
425
432
|
import abc
|
|
@@ -440,7 +447,7 @@ line 6''')
|
|
|
440
447
|
assert str(err) == """found undefined name 'x' (use explicit '\\x' syntax to bypass) (add '# NOQA' to suppress) (remove --strict to downgrade to a warning) (line 2)
|
|
441
448
|
2 + x
|
|
442
449
|
^"""
|
|
443
|
-
assert_raises(->
|
|
450
|
+
assert_raises(-> parse_with_state(d"""
|
|
444
451
|
class A(object):
|
|
445
452
|
1
|
|
446
453
|
2
|
|
@@ -458,9 +465,10 @@ line 6''')
|
|
|
458
465
|
14
|
|
459
466
|
15
|
|
460
467
|
"""), CoconutStyleError, **(dict(err_has="\n ...\n") if not PYPY else {}))
|
|
461
|
-
assert_raises(->
|
|
468
|
+
assert_raises(-> parse_with_state('["abc", "def" "ghi"]'), CoconutStyleError, err_has="implicit string concatenation")
|
|
462
469
|
|
|
463
470
|
# scope-aware undefined name tests
|
|
471
|
+
assert_raises(-> parse("abc"), CoconutStyleError, err_has="undefined name")
|
|
464
472
|
assert_raises(-> parse(d"""
|
|
465
473
|
def f():
|
|
466
474
|
x = 1
|
|
@@ -594,7 +602,7 @@ line 6''')
|
|
|
594
602
|
"""), CoconutStyleError, err_has="shadows builtin")
|
|
595
603
|
|
|
596
604
|
setup(line_numbers=False, strict=True, target="sys")
|
|
597
|
-
assert_raises(->
|
|
605
|
+
assert_raises(-> parse_with_state("await f x"), CoconutParseError)
|
|
598
606
|
|
|
599
607
|
# pure tests
|
|
600
608
|
setup(line_numbers=False, strict=True, pure=True, target="sys")
|
|
@@ -725,6 +733,20 @@ def f[T](x):
|
|
|
725
733
|
return x
|
|
726
734
|
""".strip()
|
|
727
735
|
|
|
736
|
+
setup(line_numbers=False, target="3.15")
|
|
737
|
+
# native lazy imports are only allowed at the top level
|
|
738
|
+
assert parse("lazy import json", "lenient").strip() == "lazy import json"
|
|
739
|
+
assert parse("lazy from json import dumps", "lenient").strip() == "lazy from json import dumps"
|
|
740
|
+
for lazy_src in (
|
|
741
|
+
"def f():\n lazy import json",
|
|
742
|
+
"class A:\n lazy import json",
|
|
743
|
+
"try:\n lazy import json\nexcept ImportError:\n pass",
|
|
744
|
+
"def f(): lazy import json",
|
|
745
|
+
):
|
|
746
|
+
lazy_out = parse(lazy_src, "lenient")
|
|
747
|
+
assert "lazy import" not in lazy_out, lazy_out
|
|
748
|
+
assert "_coconut_lazy_module" in lazy_out, lazy_out
|
|
749
|
+
|
|
728
750
|
setup(line_numbers=False, minify=True)
|
|
729
751
|
assert parse("123 # derp", "lenient") == "123# derp"
|
|
730
752
|
|