[case testFastParseSyntaxError]

1 +  # E: invalid syntax

[case testFastParseTypeCommentSyntaxError]

x = None # type: a : b  # E: syntax error in type comment

[case testFastParseInvalidTypeComment]

x = None # type: a + b  # E: invalid type comment or annotation

-- Function type comments are attributed to the function def line.
-- This happens in both parsers.
[case testFastParseFunctionAnnotationSyntaxError]

def f():  # E: syntax error in type comment # N: Suggestion: wrap argument types in parentheses
  # type: None -> None
  pass

[case testFastParseFunctionAnnotationSyntaxErrorSpaces]

def f():  # E: syntax error in type comment # N: Suggestion: wrap argument types in parentheses
  # type:             None -> None
  pass

[case testFastParseInvalidFunctionAnnotation]

def f(x):  # E: invalid type comment or annotation
  # type: (a + b) -> None
  pass

[case testFastParseInvalidTypes2]
# flags: --py2
# All of these should not crash
from typing import Callable, Tuple, Iterable

x = None # type: Tuple[int, str].x # E: invalid type comment or annotation
x = None # type: Iterable[x].x # E: invalid type comment or annotation
x = None # type: Tuple[x][x] # E: invalid type comment or annotation
x = None # type: Iterable[x][x] # E: invalid type comment or annotation
x = None # type: Callable[..., int][x] # E: invalid type comment or annotation
x = None # type: Callable[..., int].x # E: invalid type comment or annotation
x = None # type: Tuple[1] # E: invalid type comment or annotation

def f1(x): # E: invalid type comment or annotation
    # type: (Tuple[int, str].x) -> None
    pass
def f2(x): # E: invalid type comment or annotation
    # type: (Iterable[x].x) -> None
    pass
def f3(x): # E: invalid type comment or annotation
    # type: (Tuple[x][x]) -> None
    pass
def f4(x): # E: invalid type comment or annotation
    # type: (Iterable[x][x]) -> None
    pass
def f5(x): # E: invalid type comment or annotation
    # type: (Callable[..., int][x]) -> None
    pass
def f6(x): # E: invalid type comment or annotation
    # type: (Callable[..., int].x) -> None
    pass
def f7(x): # E: invalid type comment or annotation
    # type: (Tuple[1]) -> None
    pass


[case testFastParseInvalidTypes3]
# flags: --python-version 3.6
# All of these should not crash
from typing import Callable, Tuple, Iterable

x: Tuple[int, str].x # E: invalid type comment or annotation
x: Iterable[x].x # E: invalid type comment or annotation
x: Tuple[x][x] # E: invalid type comment or annotation
x: Iterable[x][x] # E: invalid type comment or annotation
x: Callable[..., int][x] # E: invalid type comment or annotation
x: Callable[..., int].x # E: invalid type comment or annotation
x: Tuple[1] # E: invalid type comment or annotation

x = None # type: Tuple[int, str].x # E: invalid type comment or annotation
x = None # type: Iterable[x].x # E: invalid type comment or annotation
x = None # type: Tuple[x][x] # E: invalid type comment or annotation
x = None # type: Iterable[x][x] # E: invalid type comment or annotation
x = None # type: Callable[..., int][x] # E: invalid type comment or annotation
x = None # type: Callable[..., int].x # E: invalid type comment or annotation
x = None # type: Tuple[1] # E: invalid type comment or annotation

def f1(x: Tuple[int, str].x) -> None: pass # E: invalid type comment or annotation
def f2(x: Iterable[x].x) -> None: pass # E: invalid type comment or annotation
def f3(x: Tuple[x][x]) -> None: pass # E: invalid type comment or annotation
def f4(x: Iterable[x][x]) -> None: pass # E: invalid type comment or annotation
def f5(x: Callable[..., int][x]) -> None: pass # E: invalid type comment or annotation
def f6(x: Callable[..., int].x) -> None: pass # E: invalid type comment or annotation
def f7(x: Tuple[1]) -> None: pass # E: invalid type comment or annotation

[case testFastParseProperty]

class C:
  @property
  def x(self) -> str: pass
  @x.setter
  def x(self, value: str) -> None: pass
[builtins fixtures/property.pyi]

[case testFastParseConditionalProperty]

class C:
  if bool():
    @property
    def x(self) -> str: pass
    @x.setter
    def x(self, value: str) -> None: pass
[builtins fixtures/property.pyi]

[case testFastParsePerArgumentAnnotations]

class A: pass
class B: pass
class C: pass
class D: pass
class E: pass
class F: pass
def f(a,        # type: A
      b = None, # type: B
      *args,    # type: C
      d = None, # type: D
      e,        # type: E
      **kwargs  # type: F
      ):
    reveal_type(a)      # E: Revealed type is '__main__.A'
    reveal_type(b)      # E: Revealed type is 'Union[__main__.B, None]'
    reveal_type(args)   # E: Revealed type is 'builtins.tuple[__main__.C]'
    reveal_type(d)      # E: Revealed type is 'Union[__main__.D, None]'
    reveal_type(e)      # E: Revealed type is '__main__.E'
    reveal_type(kwargs) # E: Revealed type is 'builtins.dict[builtins.str, __main__.F]'
[builtins fixtures/dict.pyi]
[out]

[case testFastParsePerArgumentAnnotationsWithReturn]

class A: pass
class B: pass
class C: pass
class D: pass
class E: pass
class F: pass
def f(a,        # type: A
      b = None, # type: B
      *args,    # type: C
      d = None, # type: D
      e,        # type: E
      **kwargs  # type: F
      ):
      # type: (...) -> int
    reveal_type(a)      # E: Revealed type is '__main__.A'
    reveal_type(b)      # E: Revealed type is 'Union[__main__.B, None]'
    reveal_type(args)   # E: Revealed type is 'builtins.tuple[__main__.C]'
    reveal_type(d)      # E: Revealed type is 'Union[__main__.D, None]'
    reveal_type(e)      # E: Revealed type is '__main__.E'
    reveal_type(kwargs) # E: Revealed type is 'builtins.dict[builtins.str, __main__.F]'
    return "not an int"  # E: Incompatible return value type (got "str", expected "int")
[builtins fixtures/dict.pyi]
[out]

[case testFastParsePerArgumentAnnotationsWithAnnotatedBareStar]

def f(*, # type: int  # E: bare * has associated type comment
      x  # type: str
      ):
      # type: (...) -> int
    pass
[builtins fixtures/dict.pyi]
[out]

[case testFastParsePerArgumentAnnotationsWithReturnAndBareStar]

def f(*,
      x  # type: str
      ):
      # type: (...) -> int
    reveal_type(x) # E: Revealed type is 'builtins.str'
    return "not an int"  # E: Incompatible return value type (got "str", expected "int")
[builtins fixtures/dict.pyi]
[out]

[case testFastParsePerArgumentAnnotations_python2]

class A: pass
class B: pass
class C: pass
class D: pass
def f(a,        # type: A
      b = None, # type: B
      *args     # type: C
      # kwargs not tested due to lack of 2.7 dict fixtures
      ):
    reveal_type(a)      # E: Revealed type is '__main__.A'
    reveal_type(b)      # E: Revealed type is 'Union[__main__.B, None]'
    reveal_type(args)   # E: Revealed type is 'builtins.tuple[__main__.C]'
[builtins fixtures/dict.pyi]
[out]

[case testFastParsePerArgumentAnnotationsWithReturn_python2]

class A: pass
class B: pass
class C: pass
class D: pass
def f(a,        # type: A
      b = None, # type: B
      *args     # type: C
      # kwargs not tested due to lack of 2.7 dict fixtures
      ):
      # type: (...) -> int
    reveal_type(a)      # E: Revealed type is '__main__.A'
    reveal_type(b)      # E: Revealed type is 'Union[__main__.B, None]'
    reveal_type(args)   # E: Revealed type is 'builtins.tuple[__main__.C]'
    return "not an int"  # E: Incompatible return value type (got "str", expected "int")
[builtins fixtures/dict.pyi]
[out]

[case testFasterParseTooManyArgumentsAnnotation]

def f():  # E: Type signature has too many arguments
    # type: (int) -> None
    pass

[case testFasterParseTooFewArgumentsAnnotation]

def f(x):  # E: Type signature has too few arguments
    # type: () -> None
    pass

[case testFasterParseTypeCommentError_python2]

from typing import Tuple
def f(a):
    # type: (Tuple(int, int)) -> int
    pass
[out]
main:3: error: invalid type comment or annotation
main:3: note: Suggestion: use Tuple[...] instead of Tuple(...)

[case testFasterParseTypeErrorList_python2]

from typing import List
def f(a):
    # type: (List(int)) -> int
    pass
[out]
main:3: error: invalid type comment or annotation
main:3: note: Suggestion: use List[...] instead of List(...)

[case testFasterParseTypeErrorCustom]

from typing import TypeVar, Generic
T = TypeVar('T')
class Foo(Generic[T]):
  pass

def f(a: Foo(int)) -> int:
    pass
[out]
main:7: error: invalid type comment or annotation
main:7: note: Suggestion: use Foo[...] instead of Foo(...)

[case testFastParseMatMul]

from typing import Any
x = None  # type: Any
x @ 1
x @= 1

[case testIncorrectTypeCommentIndex]

from typing import Dict
x = None # type: Dict[x: y]
[out]
main:3: error: syntax error in type comment

[case testPrintStatementTrailingCommaFastParser_python2]

print 0,
print 1, 2,

[case testFastParserShowsMultipleErrors]
def f(x):  # E: Type signature has too few arguments
    # type: () -> None
    pass
def g():  # E: Type signature has too many arguments
    # type: (int) -> None
    pass

[case testFastParseMalformedAssert]

assert 1, 2
assert (1, 2)  # W: Assertion is always true, perhaps remove parentheses?
assert (1, 2), 3  # W: Assertion is always true, perhaps remove parentheses?
assert ()
assert (1,)  # W: Assertion is always true, perhaps remove parentheses?

[case testFastParseAssertMessage]

assert 1
assert 1, 2
assert 1, 1+2
assert 1, 1+'test'  # E: Unsupported operand types for + ("int" and "str")
assert 1, f()  # E: Name 'f' is not defined

[case testFastParserConsistentFunctionTypes]

def f(x, y, z):
  # type: (int, int, int) -> int
  pass

def f(x,  # type: int  # E: Function has duplicate type signatures
      y,  # type: int
      z   # type: int
    ):
    # type: (int, int, int) -> int
    pass

def f(x,  # type: int
      y,  # type: int
      z   # type: int
    ):
    # type: (...) -> int
    pass

def f(x, y, z):
  # type: (int, int, int) -> int
  pass

def f(x) -> int:  # E: Function has duplicate type signatures
  # type: (int) -> int
  pass

def f(x: int, y: int, z: int):
  # type: (...) -> int
  pass

def f(x: int):  # E: Function has duplicate type signatures
  # type: (int) -> int
  pass

[case testFastParserDuplicateNames]

def f(x, y, z):
  pass

def g(x, y, x):  # E: Duplicate argument 'x' in function definition
  pass

def h(x, y, *x):  # E: Duplicate argument 'x' in function definition
  pass

def i(x, y, *z, **z):  # E: Duplicate argument 'z' in function definition
  pass

def j(x: int, y: int, *, x: int = 3):  # E: Duplicate argument 'x' in function definition
  pass

def k(*, y, z, y):  # E: Duplicate argument 'y' in function definition
  pass

lambda x, y, x: ...  # E: Duplicate argument 'x' in function definition

[case testFastParserDuplicateNames_python2]

def f(x, y, z):
  pass

def g(x, y, x):  # E: Duplicate argument 'x' in function definition
  pass

def h(x, y, *x):  # E: Duplicate argument 'x' in function definition
  pass

def i(x, y, *z, **z):  # E: Duplicate argument 'z' in function definition
  pass

def j(x, (y, y), z):  # E: Duplicate argument 'y' in function definition
  pass

def k(x, (y, x)):  # E: Duplicate argument 'x' in function definition
  pass

def l((x, y), (z, x)):  # E: Duplicate argument 'x' in function definition
  pass

def m(x, ((x, y), z)):  # E: Duplicate argument 'x' in function definition
  pass

lambda x, (y, x): None  # E: Duplicate argument 'x' in function definition

[case testNoCrashOnImportFromStar]
from pack import *
[file pack/__init__.py]
from . import *

[case testNoCrashOnImportFromStarNested]
import blamodule
[file blamodule/__init__.py]
from . import command
from . import backends

[file blamodule/backends/__init__.py]
from .Bla import Bla
reveal_type(Bla().method())  # E: Revealed type is 'builtins.str'

[file blamodule/backends/Bla.py]
from .. import *

class Bla:
    def method(self) -> str:
        return command.call()

[file blamodule/command.py]
def call() -> str: pass

[case testNoCrashOnImportFromStarPython2]
# flags: --py2
from . import * # E: No parent module -- cannot perform relative import

[case testSpuriousTrailingComma_python2]
from typing import Optional

def update_state(tid,                # type: int
                 vid,                # type: int
                 update_ts=None,     # type: Optional[float],
                 ):         # type: (...) -> str
    pass
[out]
main:3: error: Syntax error in type annotation
main:3: note: Suggestion: Is there a spurious trailing comma?
