File: parse-errors.test

package info (click to toggle)
mypy 1.19.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,412 kB
  • sloc: python: 114,754; ansic: 13,343; cpp: 11,380; makefile: 257; sh: 28
file content (445 lines) | stat: -rw-r--r-- 8,985 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
-- Test cases for parser errors. Each test case consists of two sections.
-- The first section contains [case NAME] followed by the input code, while
-- the second section contains [out] followed by the output from the parser.
--
-- The input file name in errors is "file".
--
-- Comments starting with "--" in this file will be ignored, except for lines
-- starting with "----" that are not ignored. The first two dashes of these
-- lines are interpreted as escapes and removed.

[case testInvalidFunction]
def f()
  pass
[out]
file:1: error: Invalid syntax

[case testUnexpectedIndent]
1
 2
[out]
file:2: error: Unexpected indent

[case testInconsistentIndent]
if x:
  1
   1
[out]
file:3: error: Unexpected indent

[case testInconsistentIndent2]
if x:
   1
  1
[out]
file:3: error: Unindent does not match any outer indentation level

[case testInvalidBinaryOp]
1>
a*
a+1*
[out]
file:1: error: Invalid syntax

[case testDoubleStar]
**a
[out]
file:1: error: Invalid syntax

[case testMissingSuperClass]
class A(:
  pass
[out]
file:1: error: Invalid syntax

[case testUnexpectedEof]
if 1:
[out]
file:1: error: Expected an indented block

[case testInvalidKeywordArguments1]
f(x=y, z)
[out]
file:1: error: Positional argument follows keyword argument

[case testInvalidKeywordArguments2]
f(**x, y)
[out]
file:1: error: Positional argument follows keyword argument unpacking

[case testInvalidBareAsteriskAndVarArgs2]
def f(*x: A, *) -> None: pass
[out]
file:1: error: Invalid syntax

[case testInvalidBareAsteriskAndVarArgs3]
def f(*, *x: A) -> None: pass
[out]
file:1: error: Invalid syntax

[case testInvalidBareAsteriskAndVarArgs4]
def f(*, **x: A) -> None: pass
[out]
file:1: error: Named arguments must follow bare *

[case testInvalidBareAsterisk1]
def f(*) -> None: pass
[out]
file:1: error: Named arguments must follow bare *

[case testInvalidBareAsterisk2]
def f(x, *) -> None: pass
[out]
file:1: error: Named arguments must follow bare *

[case testInvalidFuncDefArgs1]
def f(x = y, x): pass
[out]
file:1: error: Non-default argument follows default argument

[case testInvalidFuncDefArgs3]
def f(**x, y):
   pass
[out]
file:1: error: Invalid syntax

[case testInvalidFuncDefArgs4]
def f(**x, y=x):
    pass
[out]
file:1: error: Invalid syntax

[case testInvalidTypeComment]
0
x = 0 # type: A A
[out]
file:2: error: Syntax error in type comment "A A"

[case testInvalidTypeComment2]
0
x = 0 # type: A[
[out]
file:2: error: Syntax error in type comment "A["

[case testInvalidTypeComment3]
0
x = 0 # type:
[out]
file:2: error: Syntax error in type comment ""

[case testInvalidTypeComment4]
0
x = 0 # type: *
[out]
file:2: error: Syntax error in type comment "*"

[case testInvalidTypeComment5]
0
x = 0 # type:# some comment
[out]
file:2: error: Syntax error in type comment ""

[case testInvalidTypeComment6]
0
x = 0 # type: *# comment #6
[out]
file:2: error: Syntax error in type comment "*"

[case testInvalidTypeComment7]
0
x = 0 # type: A B #comment #7
[out]
file:2: error: Syntax error in type comment "A B"

[case testMissingBracket]
def foo(
[out]
file:1: error: Unexpected EOF while parsing
[out version>=3.10]
file:1: error: '(' was never closed

[case testInvalidSignatureInComment1]
def f(): # type: x
  pass
[out]
file:1: error: Syntax error in type comment "x"
file:1: note: Suggestion: wrap argument types in parentheses

[case testInvalidSignatureInComment2]
def f(): # type:
  pass
[out]
file:1: error: Syntax error in type comment ""

[case testInvalidSignatureInComment3]
def f(): # type: (
  pass
[out]
file:1: error: Syntax error in type comment "("

[case testInvalidSignatureInComment4]
def f(): # type: (.
  pass
[out]
file:1: error: Syntax error in type comment "(."

[case testInvalidSignatureInComment5]
def f(): # type: (x
  pass
[out]
file:1: error: Syntax error in type comment "(x"

[case testInvalidSignatureInComment6]
def f(): # type: (x)
  pass
[out]
file:1: error: Syntax error in type comment "(x)"

[case testInvalidSignatureInComment7]
def f(): # type: (x) -
  pass
[out]
file:1: error: Syntax error in type comment "(x) -"

[case testInvalidSignatureInComment8]
def f(): # type: (x) ->
  pass
[out]
file:1: error: Syntax error in type comment "(x) ->"

[case testInvalidSignatureInComment9]
def f(): # type: (x) -> .
  pass
[out]
file:1: error: Syntax error in type comment "(x) -> ."

[case testInvalidSignatureInComment10]
def f(): # type: (x) -> x x
  pass
[out]
file:1: error: Syntax error in type comment "(x) -> x x"

[case testInvalidSignatureInComment11]
def f(): # type: # abc comment
  pass
[out]
file:1: error: Syntax error in type comment ""

[case testInvalidSignatureInComment12]
def f(): # type: (x) -> x x # comment #2
  pass
[out]
file:1: error: Syntax error in type comment "(x) -> x x"


[case testDuplicateSignatures1]
def f() -> None: # type: () -> None
  pass
def f(): # type: () -> None
    pass
[out]
file:1: error: Function has duplicate type signatures

[case testDuplicateSignatures2]
def f(x, y: Z): # type: (x, y) -> z
  pass
[out]
file:1: error: Function has duplicate type signatures

[case testTooManyTypes]
def f(x, y): # type: (X, Y, Z) -> z
  pass
[out]
file:1: error: Type signature has too many arguments

[case testTooFewTypes]
def f(x, y): # type: (X) -> z
  pass
[out]
file:1: error: Type signature has too few arguments

[case testCommentFunctionAnnotationVarArgMispatch-skip]
# see mypy issue #1997
def f(x): # type: (*X) -> Y
    pass
def g(*x): # type: (X) -> Y
    pass
[out]
file:1: error: Inconsistent use of "*" in function signature
file:3: error: Inconsistent use of "*" in function signature

[case testCommentFunctionAnnotationVarArgMispatch2-skip]
# see mypy issue #1997
def f(*x, **y): # type: (**X, *Y) -> Z
    pass
def g(*x, **y): # type: (*X, *Y) -> Z
    pass
[out]
file:1: error: Inconsistent use of "*" in function signature
file:3: error: Syntax error in type comment
file:3: error: Inconsistent use of "*" in function signature
file:3: error: Inconsistent use of "**" in function signature

[case testPrintStatementInPython3]
print 1
[out]
file:1: error: Missing parentheses in call to 'print'. Did you mean print(1)?

[case testInvalidConditionInConditionalExpression]
1 if 2, 3 else 4
[out]
file:1: error: Invalid syntax

[case testInvalidConditionInConditionalExpression2]
1 if x for y in z else 4
[out]
file:1: error: Invalid syntax

[case testInvalidConditionInConditionalExpression3]
1 if x else for y in z
[out]
file:1: error: Invalid syntax

[case testYieldFromNotRightParameter]
def f():
    yield from
[out]
file:2: error: Invalid syntax

[case testYieldFromAfterReturn]
def f():
    return yield from h()
[out]
file:2: error: Invalid syntax

[case testImportDotModule]
import .x
[out]
file:1: error: Invalid syntax

[case testImportDot]
import .
[out]
file:1: error: Invalid syntax

[case testInvalidFunctionName]
def while(): pass
[out]
file:1: error: Invalid syntax

[case testInvalidEllipsis1]
...0
..._
...a
[out]
file:1: error: Invalid syntax

[case testBlockStatementInSingleLineIf]
if 1: if 2: pass
[out]
file:1: error: Invalid syntax

[case testBlockStatementInSingleLineIf2]
if 1: while 2: pass
[out]
file:1: error: Invalid syntax

[case testBlockStatementInSingleLineIf3]
if 1: for x in y: pass
[out]
file:1: error: Invalid syntax

[case testUnexpectedEllipsis]
a = a...
[out]
file:1: error: Invalid syntax

[case testParseErrorBeforeUnicodeLiteral]
x u'y'
[out]
file:1: error: Invalid syntax

[case testParseErrorInExtendedSlicing]
x[:,
[out]
file:1: error: Unexpected EOF while parsing

[case testParseErrorInExtendedSlicing2]
x[:,::
[out]
file:1: error: Unexpected EOF while parsing

[case testParseErrorInExtendedSlicing3]
x[:,:
[out]
file:1: error: Unexpected EOF while parsing

[case testInvalidEncoding]
# foo
# coding: uft-8
[out]
file:0: error: Unknown encoding: uft-8

[case testInvalidEncoding2]
# coding=Uft.8
[out]
file:0: error: Unknown encoding: Uft.8

[case testInvalidEncoding3]
#!/usr/bin python
# vim: set fileencoding=uft8 :
[out]
file:0: error: Unknown encoding: uft8

[case testDoubleEncoding]
# coding: uft8
# coding: utf8
# The first coding cookie should be used and fail.
[out]
file:0: error: Unknown encoding: uft8

[case testDoubleEncoding2]
# Again the first cookie should be used and fail.
# coding: uft8
# coding: utf8
[out]
file:0: error: Unknown encoding: uft8

[case testLongLiteralInPython3]
2L
0x2L
[out]
file:1: error: Invalid syntax

[case testPython2LegacyInequalityInPython3]
1 <> 2
[out]
file:1: error: Invalid syntax

[case testLambdaInListComprehensionInPython3]
([ 0 for x in 1, 2 if 3 ])
[out]
file:1: error: Invalid syntax

[case testTupleArgListInPython3]
def f(x, (y, z)): pass
[out]
file:1: error: Invalid syntax

[case testBackquoteInPython3]
`1 + 2`
[out]
file:1: error: Invalid syntax

[case testSmartQuotes]
foo = ‘bar’
[out]
file:1: error: Invalid character '‘' (U+2018)

[case testExceptCommaInPython3]
try:
    pass
except KeyError, IndexError:
    pass
[out]
file:3: error: Invalid syntax