| 1 |
-- Test cases for parser errors. Each test case consists of two sections. |
| 2 |
-- The first section contains [case NAME] followed by the input code, while |
| 3 |
-- the second section contains [out] followed by the output from the parser. |
| 4 |
-- |
| 5 |
-- The input file name in errors is "file". |
| 6 |
-- |
| 7 |
-- Comments starting with "--" in this file will be ignored, except for lines |
| 8 |
-- starting with "----" that are not ignored. The first two dashes of these |
| 9 |
-- lines are interpreted as escapes and removed. |
| 10 |
|
| 11 |
[case testInvalidFunction] |
| 12 |
def f() |
| 13 |
pass |
| 14 |
[out] |
| 15 |
file:1: error: Expected ':' |
| 16 |
|
| 17 |
[case testUnexpectedIndent] |
| 18 |
1 |
| 19 |
2 |
| 20 |
[out] |
| 21 |
file:2: error: Unexpected indent |
| 22 |
|
| 23 |
[case testInconsistentIndent] |
| 24 |
if x: |
| 25 |
1 |
| 26 |
1 |
| 27 |
[out] |
| 28 |
file:3: error: Unexpected indent |
| 29 |
|
| 30 |
[case testInconsistentIndent2] |
| 31 |
if x: |
| 32 |
1 |
| 33 |
1 |
| 34 |
[out] |
| 35 |
file:3: error: Unindent does not match any outer indentation level |
| 36 |
|
| 37 |
[case testInvalidBinaryOp] |
| 38 |
1> |
| 39 |
a* |
| 40 |
a+1* |
| 41 |
[out] |
| 42 |
file:1: error: Invalid syntax |
| 43 |
|
| 44 |
[case testDoubleStar] |
| 45 |
**a |
| 46 |
[out] |
| 47 |
file:1: error: Invalid syntax |
| 48 |
|
| 49 |
[case testMissingSuperClass] |
| 50 |
class A(: |
| 51 |
pass |
| 52 |
[out] |
| 53 |
file:1: error: Invalid syntax |
| 54 |
|
| 55 |
[case testUnexpectedEof] |
| 56 |
if 1: |
| 57 |
[out] |
| 58 |
file:1: error: Expected an indented block after 'if' statement on line 1 |
| 59 |
|
| 60 |
[case testInvalidKeywordArguments1] |
| 61 |
f(x=y, z) |
| 62 |
[out] |
| 63 |
file:1: error: Positional argument follows keyword argument |
| 64 |
|
| 65 |
[case testInvalidKeywordArguments2] |
| 66 |
f(**x, y) |
| 67 |
[out] |
| 68 |
file:1: error: Positional argument follows keyword argument unpacking |
| 69 |
|
| 70 |
[case testInvalidBareAsteriskAndVarArgs2] |
| 71 |
def f(*x: A, *) -> None: pass |
| 72 |
[out] |
| 73 |
file:1: error: Invalid syntax |
| 74 |
|
| 75 |
[case testInvalidBareAsteriskAndVarArgs3] |
| 76 |
def f(*, *x: A) -> None: pass |
| 77 |
[out] |
| 78 |
file:1: error: Invalid syntax |
| 79 |
|
| 80 |
[case testInvalidBareAsteriskAndVarArgs4] |
| 81 |
def f(*, **x: A) -> None: pass |
| 82 |
[out] |
| 83 |
file:1: error: Named arguments must follow bare * |
| 84 |
|
| 85 |
[case testInvalidBareAsterisk1] |
| 86 |
def f(*) -> None: pass |
| 87 |
[out] |
| 88 |
file:1: error: Named arguments must follow bare * |
| 89 |
|
| 90 |
[case testInvalidBareAsterisk2] |
| 91 |
def f(x, *) -> None: pass |
| 92 |
[out] |
| 93 |
file:1: error: Named arguments must follow bare * |
| 94 |
|
| 95 |
[case testInvalidFuncDefArgs1] |
| 96 |
def f(x = y, x): pass |
| 97 |
[out] |
| 98 |
file:1: error: Non-default argument follows default argument |
| 99 |
|
| 100 |
[case testInvalidFuncDefArgs3] |
| 101 |
def f(**x, y): |
| 102 |
pass |
| 103 |
[out] |
| 104 |
file:1: error: Invalid syntax |
| 105 |
|
| 106 |
[case testInvalidFuncDefArgs4] |
| 107 |
def f(**x, y=x): |
| 108 |
pass |
| 109 |
[out] |
| 110 |
file:1: error: Invalid syntax |
| 111 |
|
| 112 |
[case testInvalidTypeComment] |
| 113 |
0 |
| 114 |
x = 0 # type: A A |
| 115 |
[out] |
| 116 |
file:2: error: Syntax error in type comment "A A" |
| 117 |
|
| 118 |
[case testInvalidTypeComment2] |
| 119 |
0 |
| 120 |
x = 0 # type: A[ |
| 121 |
[out] |
| 122 |
file:2: error: Syntax error in type comment "A[" |
| 123 |
|
| 124 |
[case testInvalidTypeComment3] |
| 125 |
0 |
| 126 |
x = 0 # type: |
| 127 |
[out] |
| 128 |
file:2: error: Syntax error in type comment "" |
| 129 |
|
| 130 |
[case testInvalidTypeComment4] |
| 131 |
0 |
| 132 |
x = 0 # type: * |
| 133 |
[out] |
| 134 |
file:2: error: Syntax error in type comment "*" |
| 135 |
|
| 136 |
[case testInvalidTypeComment5] |
| 137 |
0 |
| 138 |
x = 0 # type:# some comment |
| 139 |
[out] |
| 140 |
file:2: error: Syntax error in type comment "" |
| 141 |
|
| 142 |
[case testInvalidTypeComment6] |
| 143 |
0 |
| 144 |
x = 0 # type: *# comment #6 |
| 145 |
[out] |
| 146 |
file:2: error: Syntax error in type comment "*" |
| 147 |
|
| 148 |
[case testInvalidTypeComment7] |
| 149 |
0 |
| 150 |
x = 0 # type: A B #comment #7 |
| 151 |
[out] |
| 152 |
file:2: error: Syntax error in type comment "A B" |
| 153 |
|
| 154 |
[case testMissingBracket] |
| 155 |
def foo( |
| 156 |
[out] |
| 157 |
file:1: error: '(' was never closed |
| 158 |
|
| 159 |
[case testInvalidSignatureInComment1] |
| 160 |
def f(): # type: x |
| 161 |
pass |
| 162 |
[out] |
| 163 |
file:1: error: Syntax error in type comment "x" |
| 164 |
file:1: note: Suggestion: wrap argument types in parentheses |
| 165 |
|
| 166 |
[case testInvalidSignatureInComment2] |
| 167 |
def f(): # type: |
| 168 |
pass |
| 169 |
[out] |
| 170 |
file:1: error: Syntax error in type comment "" |
| 171 |
|
| 172 |
[case testInvalidSignatureInComment3] |
| 173 |
def f(): # type: ( |
| 174 |
pass |
| 175 |
[out] |
| 176 |
file:1: error: Syntax error in type comment "(" |
| 177 |
|
| 178 |
[case testInvalidSignatureInComment4] |
| 179 |
def f(): # type: (. |
| 180 |
pass |
| 181 |
[out] |
| 182 |
file:1: error: Syntax error in type comment "(." |
| 183 |
|
| 184 |
[case testInvalidSignatureInComment5] |
| 185 |
def f(): # type: (x |
| 186 |
pass |
| 187 |
[out] |
| 188 |
file:1: error: Syntax error in type comment "(x" |
| 189 |
|
| 190 |
[case testInvalidSignatureInComment6] |
| 191 |
def f(): # type: (x) |
| 192 |
pass |
| 193 |
[out] |
| 194 |
file:1: error: Syntax error in type comment "(x)" |
| 195 |
|
| 196 |
[case testInvalidSignatureInComment7] |
| 197 |
def f(): # type: (x) - |
| 198 |
pass |
| 199 |
[out] |
| 200 |
file:1: error: Syntax error in type comment "(x) -" |
| 201 |
|
| 202 |
[case testInvalidSignatureInComment8] |
| 203 |
def f(): # type: (x) -> |
| 204 |
pass |
| 205 |
[out] |
| 206 |
file:1: error: Syntax error in type comment "(x) ->" |
| 207 |
|
| 208 |
[case testInvalidSignatureInComment9] |
| 209 |
def f(): # type: (x) -> . |
| 210 |
pass |
| 211 |
[out] |
| 212 |
file:1: error: Syntax error in type comment "(x) -> ." |
| 213 |
|
| 214 |
[case testInvalidSignatureInComment10] |
| 215 |
def f(): # type: (x) -> x x |
| 216 |
pass |
| 217 |
[out] |
| 218 |
file:1: error: Syntax error in type comment "(x) -> x x" |
| 219 |
|
| 220 |
[case testInvalidSignatureInComment11] |
| 221 |
def f(): # type: # abc comment |
| 222 |
pass |
| 223 |
[out] |
| 224 |
file:1: error: Syntax error in type comment "" |
| 225 |
|
| 226 |
[case testInvalidSignatureInComment12] |
| 227 |
def f(): # type: (x) -> x x # comment #2 |
| 228 |
pass |
| 229 |
[out] |
| 230 |
file:1: error: Syntax error in type comment "(x) -> x x" |
| 231 |
|
| 232 |
|
| 233 |
[case testDuplicateSignatures1] |
| 234 |
def f() -> None: # type: () -> None |
| 235 |
pass |
| 236 |
def f(): # type: () -> None |
| 237 |
pass |
| 238 |
[out] |
| 239 |
file:1: error: Function has duplicate type signatures |
| 240 |
|
| 241 |
[case testDuplicateSignatures2] |
| 242 |
def f(x, y: Z): # type: (x, y) -> z |
| 243 |
pass |
| 244 |
[out] |
| 245 |
file:1: error: Function has duplicate type signatures |
| 246 |
|
| 247 |
[case testTooManyTypes] |
| 248 |
def f(x, y): # type: (X, Y, Z) -> z |
| 249 |
pass |
| 250 |
[out] |
| 251 |
file:1: error: Type signature has too many parameters |
| 252 |
|
| 253 |
[case testTooFewTypes] |
| 254 |
def f(x, y): # type: (X) -> z |
| 255 |
pass |
| 256 |
[out] |
| 257 |
file:1: error: Type signature has too few parameters |
| 258 |
|
| 259 |
[case testCommentFunctionAnnotationVarArgMispatch-skip] |
| 260 |
# see mypy issue #1997 |
| 261 |
def f(x): # type: (*X) -> Y |
| 262 |
pass |
| 263 |
def g(*x): # type: (X) -> Y |
| 264 |
pass |
| 265 |
[out] |
| 266 |
file:1: error: Inconsistent use of "*" in function signature |
| 267 |
file:3: error: Inconsistent use of "*" in function signature |
| 268 |
|
| 269 |
[case testCommentFunctionAnnotationVarArgMispatch2-skip] |
| 270 |
# see mypy issue #1997 |
| 271 |
def f(*x, **y): # type: (**X, *Y) -> Z |
| 272 |
pass |
| 273 |
def g(*x, **y): # type: (*X, *Y) -> Z |
| 274 |
pass |
| 275 |
[out] |
| 276 |
file:1: error: Inconsistent use of "*" in function signature |
| 277 |
file:3: error: Syntax error in type comment |
| 278 |
file:3: error: Inconsistent use of "*" in function signature |
| 279 |
file:3: error: Inconsistent use of "**" in function signature |
| 280 |
|
| 281 |
[case testPrintStatementInPython3] |
| 282 |
print 1 |
| 283 |
[out] |
| 284 |
file:1: error: Missing parentheses in call to 'print'. Did you mean print(...)? |
| 285 |
|
| 286 |
[case testInvalidConditionInConditionalExpression] |
| 287 |
1 if 2, 3 else 4 |
| 288 |
[out] |
| 289 |
file:1: error: Expected 'else' after 'if' expression |
| 290 |
|
| 291 |
[case testInvalidConditionInConditionalExpression2] |
| 292 |
1 if x for y in z else 4 |
| 293 |
[out] |
| 294 |
file:1: error: Expected 'else' after 'if' expression |
| 295 |
|
| 296 |
[case testInvalidConditionInConditionalExpression3] |
| 297 |
1 if x else for y in z |
| 298 |
[out] |
| 299 |
file:1: error: Invalid syntax |
| 300 |
|
| 301 |
[case testYieldFromNotRightParameter] |
| 302 |
def f(): |
| 303 |
yield from |
| 304 |
[out] |
| 305 |
file:2: error: Invalid syntax |
| 306 |
|
| 307 |
[case testYieldFromAfterReturn] |
| 308 |
def f(): |
| 309 |
return yield from h() |
| 310 |
[out] |
| 311 |
file:2: error: Invalid syntax |
| 312 |
|
| 313 |
[case testImportDotModule] |
| 314 |
import .x |
| 315 |
[out] |
| 316 |
file:1: error: Invalid syntax |
| 317 |
|
| 318 |
[case testImportDot] |
| 319 |
import . |
| 320 |
[out] |
| 321 |
file:1: error: Invalid syntax |
| 322 |
|
| 323 |
[case testInvalidFunctionName] |
| 324 |
def while(): pass |
| 325 |
[out] |
| 326 |
file:1: error: Invalid syntax |
| 327 |
|
| 328 |
[case testInvalidEllipsis1] |
| 329 |
...0 |
| 330 |
..._ |
| 331 |
...a |
| 332 |
[out] |
| 333 |
file:1: error: Invalid syntax |
| 334 |
|
| 335 |
[case testBlockStatementInSingleLineIf] |
| 336 |
if 1: if 2: pass |
| 337 |
[out] |
| 338 |
file:1: error: Invalid syntax |
| 339 |
|
| 340 |
[case testBlockStatementInSingleLineIf2] |
| 341 |
if 1: while 2: pass |
| 342 |
[out] |
| 343 |
file:1: error: Invalid syntax |
| 344 |
|
| 345 |
[case testBlockStatementInSingleLineIf3] |
| 346 |
if 1: for x in y: pass |
| 347 |
[out] |
| 348 |
file:1: error: Invalid syntax |
| 349 |
|
| 350 |
[case testUnexpectedEllipsis] |
| 351 |
a = a... |
| 352 |
[out] |
| 353 |
file:1: error: Invalid syntax |
| 354 |
|
| 355 |
[case testParseErrorBeforeUnicodeLiteral] |
| 356 |
x u'y' |
| 357 |
[out] |
| 358 |
file:1: error: Invalid syntax |
| 359 |
|
| 360 |
[case testParseErrorInExtendedSlicing] |
| 361 |
x[:, |
| 362 |
[out] |
| 363 |
file:1: error: '[' was never closed |
| 364 |
|
| 365 |
[case testParseErrorInExtendedSlicing2] |
| 366 |
x[:,:: |
| 367 |
[out] |
| 368 |
file:1: error: '[' was never closed |
| 369 |
|
| 370 |
[case testParseErrorInExtendedSlicing3] |
| 371 |
x[:,: |
| 372 |
[out] |
| 373 |
file:1: error: '[' was never closed |
| 374 |
|
| 375 |
[case testInvalidEncoding] |
| 376 |
# foo |
| 377 |
# coding: uft-8 |
| 378 |
[out] |
| 379 |
file:0: error: Unknown encoding: uft-8 |
| 380 |
|
| 381 |
[case testInvalidEncoding2] |
| 382 |
# coding=Uft.8 |
| 383 |
[out] |
| 384 |
file:0: error: Unknown encoding: Uft.8 |
| 385 |
|
| 386 |
[case testInvalidEncoding3] |
| 387 |
#!/usr/bin python |
| 388 |
# vim: set fileencoding=uft8 : |
| 389 |
[out] |
| 390 |
file:0: error: Unknown encoding: uft8 |
| 391 |
|
| 392 |
[case testDoubleEncoding] |
| 393 |
# coding: uft8 |
| 394 |
# coding: utf8 |
| 395 |
# The first coding cookie should be used and fail. |
| 396 |
[out] |
| 397 |
file:0: error: Unknown encoding: uft8 |
| 398 |
|
| 399 |
[case testDoubleEncoding2] |
| 400 |
# Again the first cookie should be used and fail. |
| 401 |
# coding: uft8 |
| 402 |
# coding: utf8 |
| 403 |
[out] |
| 404 |
file:0: error: Unknown encoding: uft8 |
| 405 |
|
| 406 |
[case testLongLiteralInPython3] |
| 407 |
2L |
| 408 |
0x2L |
| 409 |
[out] |
| 410 |
file:1: error: Invalid decimal literal |
| 411 |
|
| 412 |
[case testPython2LegacyInequalityInPython3] |
| 413 |
1 <> 2 |
| 414 |
[out] |
| 415 |
file:1: error: Invalid syntax |
| 416 |
|
| 417 |
[case testLambdaInListComprehensionInPython3] |
| 418 |
([ 0 for x in 1, 2 if 3 ]) |
| 419 |
[out] |
| 420 |
file:1: error: Invalid syntax |
| 421 |
|
| 422 |
[case testTupleArgListInPython3] |
| 423 |
def f(x, (y, z)): pass |
| 424 |
[out] |
| 425 |
file:1: error: Invalid syntax |
| 426 |
|
| 427 |
[case testBackquoteInPython3] |
| 428 |
`1 + 2` |
| 429 |
[out] |
| 430 |
file:1: error: Invalid syntax |
| 431 |
|
| 432 |
[case testSmartQuotes] |
| 433 |
foo = ‘bar’ |
| 434 |
[out] |
| 435 |
file:1: error: Invalid character '‘' (U+2018) |
| 436 |
|
| 437 |
[case testExceptCommaInPython3] |
| 438 |
try: |
| 439 |
pass |
| 440 |
except KeyError, IndexError: |
| 441 |
pass |
| 442 |
[out] |
| 443 |
file:3: error: Multiple exception types must be parenthesized |