-- 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 ':' [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 after 'if' statement on line 1 [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: '(' 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 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: Missing parentheses in call to 'print'. Did you mean print(...)? [case testInvalidConditionInConditionalExpression] 1 if 2, 3 else 4 [out] file:1: error: Expected 'else' after 'if' expression [case testInvalidConditionInConditionalExpression2] 1 if x for y in z else 4 [out] file:1: error: Expected 'else' after 'if' expression [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: '[' was never closed [case testParseErrorInExtendedSlicing2] x[:,:: [out] file:1: error: '[' was never closed [case testParseErrorInExtendedSlicing3] x[:,: [out] file:1: error: '[' was never closed [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 decimal literal [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: Multiple exception types must be parenthesized