| -- 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: Expected `:`, found newline | |
| [case testUnexpectedIndent] | |
| 1 | |
| 2 | |
| [out] | |
| file:2: error: Unexpected indentation | |
| [case testInconsistentIndent] | |
| if x: | |
| 1 | |
| 1 | |
| [out] | |
| file:3: error: Unexpected indentation | |
| [case testInconsistentIndent2] | |
| if x: | |
| 1 | |
| 1 | |
| [out] | |
| file:3: error: Unindent does not match any outer indentation level | |
| file:3: error: Expected dedent, found end of file | |
| [case testInvalidBinaryOp] | |
| 1> | |
| a* | |
| a+1* | |
| [out] | |
| file:1: error: Expected an expression | |
| file:2: error: Expected an expression | |
| file:3: error: Expected an expression | |
| [case testDoubleStar] | |
| **a | |
| [out] | |
| file:1: error: Expected an expression | |
| [case testMissingSuperClass] | |
| class A(: | |
| pass | |
| [out] | |
| file:1: error: Expected an expression or a ')' | |
| file:1: error: Expected `)`, found newline | |
| [case testUnexpectedEof] | |
| if 1: | |
| [out] | |
| file:1: error: Expected an indented block after `if` statement | |
| [case testInvalidKeywordArguments1] | |
| f(x=y, z) | |
| [out] | |
| file:1: error: Positional argument cannot follow keyword argument | |
| [case testInvalidKeywordArguments2] | |
| f(**x, y) | |
| [out] | |
| file:1: error: Positional argument cannot follow keyword argument unpacking | |
| [case testInvalidBareAsteriskAndVarArgs2] | |
| def f(*x: A, *) -> None: pass | |
| [out] | |
| file:1: error: Keyword-only parameter separator not allowed after '*' parameter | |
| [case testInvalidBareAsteriskAndVarArgs3] | |
| def f(*, *x: A) -> None: pass | |
| [out] | |
| file:1: error: Only one '*' parameter allowed | |
| [case testInvalidBareAsteriskAndVarArgs4] | |
| def f(*, **x: A) -> None: pass | |
| [out] | |
| file:1: error: Expected one or more keyword parameter after `*` separator | |
| [case testInvalidBareAsterisk1] | |
| def f(*) -> None: pass | |
| [out] | |
| file:1: error: Expected one or more keyword parameter after `*` separator | |
| [case testInvalidBareAsterisk2] | |
| def f(x, *) -> None: pass | |
| [out] | |
| file:1: error: Expected one or more keyword parameter after `*` separator | |
| [case testInvalidFuncDefArgs1] | |
| def f(x = y, x): pass | |
| [out] | |
| file:1: error: Duplicate parameter "x" in function definition | |
| file:1: error: Parameter without a default cannot follow a parameter with a default | |
| [case testInvalidFuncDefArgs2] | |
| def f(x = y, z): pass | |
| [out] | |
| file:1: error: Parameter without a default cannot follow a parameter with a default | |
| [case testInvalidFuncDefArgs3] | |
| def f(**x, y): | |
| pass | |
| [out] | |
| file:1: error: Parameter cannot follow var-keyword parameter | |
| [case testInvalidFuncDefArgs4] | |
| def f(**x, y=x): | |
| pass | |
| [out] | |
| file:1: error: Parameter cannot follow var-keyword parameter | |
| [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 | |
| -- TODO: new parser silently ignores regular type comment in this situation. | |
| -- For various reasons, matching behavior with the old parser is non-trivial. | |
| [case testInvalidSignatureInComment1_old_parser] | |
| 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_old_parser] | |
| 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: Type signature has too many parameters | |
| [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 parameters | |
| [case testTooFewTypes] | |
| def f(x, y): # type: (X) -> z | |
| pass | |
| [out] | |
| file:1: error: Type signature has too few parameters | |
| [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: Simple statements must be separated by newlines or semicolons | |
| [case testInvalidConditionInConditionalExpression] | |
| 1 if 2, 3 else 4 | |
| [out] | |
| file:1: error: Expected `else`, found `,` | |
| file:1: error: Expected a statement | |
| [case testInvalidConditionInConditionalExpression2] | |
| 1 if x for y in z else 4 | |
| [out] | |
| file:1: error: Expected `else`, found `for` | |
| file:1: error: Simple statements must be separated by newlines or semicolons | |
| file:1: error: Expected a statement | |
| [case testInvalidConditionInConditionalExpression3] | |
| 1 if x else for y in z | |
| [out] | |
| file:1: error: Expected an identifier, but found a keyword `for` that cannot be used here | |
| file:1: error: Simple statements must be separated by newlines or semicolons | |
| [case testYieldFromNotRightParameter] | |
| def f(): | |
| yield from | |
| [out] | |
| file:2: error: Expected an expression | |
| [case testYieldFromAfterReturn] | |
| def f(): | |
| return yield from h() | |
| [out] | |
| file:2: error: Yield expression cannot be used here | |
| [case testImportDotModule] | |
| import .x | |
| [out] | |
| file:1: error: Expected an import name | |
| [case testImportDot] | |
| import . | |
| [out] | |
| file:1: error: Expected an import name | |
| file:1: error: Expected one or more symbol names after import | |
| [case testInvalidFunctionName] | |
| def while(): pass | |
| [out] | |
| file:1: error: Expected an identifier, but found a keyword `while` that cannot be used here | |
| [case testInvalidEllipsis1] | |
| ...0 | |
| ..._ | |
| ...a | |
| [out] | |
| file:1: error: Simple statements must be separated by newlines or semicolons | |
| file:2: error: Simple statements must be separated by newlines or semicolons | |
| file:3: error: Simple statements must be separated by newlines or semicolons | |
| [case testBlockStatementInSingleLineIf] | |
| if 1: if 2: pass | |
| [out] | |
| file:1: error: Expected a simple statement | |
| [case testBlockStatementInSingleLineIf2] | |
| if 1: while 2: pass | |
| [out] | |
| file:1: error: Expected a simple statement | |
| [case testBlockStatementInSingleLineIf3] | |
| if 1: for x in y: pass | |
| [out] | |
| file:1: error: Expected a simple statement | |
| [case testUnexpectedEllipsis] | |
| a = a... | |
| [out] | |
| file:1: error: Simple statements must be separated by newlines or semicolons | |
| [case testParseErrorBeforeUnicodeLiteral] | |
| x u'y' | |
| [out] | |
| file:1: error: Simple statements must be separated by newlines or semicolons | |
| [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 | |
| -- TODO: new parser only suports UTF-8 and ignores coding declarations | |
| [case testInvalidEncoding_old_parser] | |
| # foo | |
| # coding: uft-8 | |
| [out] | |
| file:0: error: Unknown encoding: uft-8 | |
| [case testInvalidEncoding2_old_parser] | |
| # coding=Uft.8 | |
| [out] | |
| file:0: error: Unknown encoding: Uft.8 | |
| [case testInvalidEncoding3_old_parser] | |
| #!/usr/bin python | |
| # vim: set fileencoding=uft8 : | |
| [out] | |
| file:0: error: Unknown encoding: uft8 | |
| [case testDoubleEncoding_old_parser] | |
| # coding: uft8 | |
| # coding: utf8 | |
| # The first coding cookie should be used and fail. | |
| [out] | |
| file:0: error: Unknown encoding: uft8 | |
| [case testDoubleEncoding2_old_parser] | |
| # 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: Simple statements must be separated by newlines or semicolons | |
| file:2: error: Simple statements must be separated by newlines or semicolons | |
| [case testPython2LegacyInequalityInPython3] | |
| 1 <> 2 | |
| [out] | |
| file:1: error: Expected an expression | |
| [case testLambdaInListComprehensionInPython3] | |
| ([ 0 for x in 1, 2 if 3 ]) | |
| [out] | |
| file:1: error: Expected `]`, found `,` | |
| file:1: error: Expected `else`, found `]` | |
| [case testTupleArgListInPython3] | |
| def f(x, (y, z)): pass | |
| [out] | |
| file:1: error: Expected `)`, found `(` | |
| file:1: error: Expected newline, found `)` | |
| file:1: error: Expected a statement | |
| [case testBackquoteInPython3] | |
| `1 + 2` | |
| [out] | |
| file:1: error: Got unexpected token ` | |
| file:1: error: Expected a statement | |
| [case testSmartQuotes] | |
| foo = βbarβ | |
| [out] | |
| file:1: error: Got unexpected token β | |
| file:1: error: Got unexpected token β | |
| file:1: error: Expected a statement | |
| [case testExceptCommaInPython3] | |
| try: | |
| pass | |
| except KeyError, IndexError: | |
| pass | |
| [out] | |
| file:3: error: Multiple exception types must be parenthesized |