| [case testFastParseSyntaxError] | |
| 1 + # E: invalid syntax | |
| [case testFastParseTypeCommentSyntaxError] | |
| x = None # type: a : b # E: syntax error in type comment 'a : b' | |
| [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 'None -> None' # N: Suggestion: wrap argument types in parentheses | |
| # type: None -> None | |
| pass | |
| [case testFastParseFunctionAnnotationSyntaxErrorSpaces] | |
| def f(): # E: syntax error in type comment 'None -> None' # 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 | |
| a = None # type: Iterable[x].x # E: Invalid type comment or annotation | |
| b = None # type: Tuple[x][x] # E: Invalid type comment or annotation | |
| c = None # type: Iterable[x][x] # E: Invalid type comment or annotation | |
| d = None # type: Callable[..., int][x] # E: Invalid type comment or annotation | |
| e = None # type: Callable[..., int].x # 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 | |
| [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 | |
| a: Iterable[x].x # E: Invalid type comment or annotation | |
| b: Tuple[x][x] # E: Invalid type comment or annotation | |
| c: Iterable[x][x] # E: Invalid type comment or annotation | |
| d: Callable[..., int][x] # E: Invalid type comment or annotation | |
| e: Callable[..., int].x # E: Invalid type comment or annotation | |
| f = None # type: Tuple[int, str].x # E: Invalid type comment or annotation | |
| g = None # type: Iterable[x].x # E: Invalid type comment or annotation | |
| h = None # type: Tuple[x][x] # E: Invalid type comment or annotation | |
| i = None # type: Iterable[x][x] # E: Invalid type comment or annotation | |
| j = None # type: Callable[..., int][x] # E: Invalid type comment or annotation | |
| k = None # type: Callable[..., int].x # 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 | |
| [case testFastParseTypeWithIgnore] | |
| def f(x, # type: x # type: ignore | |
| ): | |
| # type: (...) -> None | |
| pass | |
| [case testFastParseVariableTypeWithIgnore] | |
| x = 1 # type: str # type: ignore | |
| [case testFastParseVariableTypeWithIgnoreNoSpace] | |
| x = 1 # type: str #type:ignore | |
| [case testFastParseVariableTypeWithIgnoreAndComment] | |
| x = 1 # type: str # type: ignore # comment | |
| [case testFastParseTypeWithIgnoreWithStmt] | |
| with open('test', 'r') as f: # type: int # type: ignore | |
| pass | |
| [case testFastParseTypeWithIgnoreForStmt] | |
| for i in (1, 2, 3, 100): # type: str # type: ignore | |
| pass | |
| [case testFastParseVariableCommentThenIgnore] | |
| a="test" # type: int #comment # type: ignore # E: Incompatible types in assignment (expression has type "str", variable has type "int") | |
| [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) # N: Revealed type is '__main__.A' | |
| reveal_type(b) # N: Revealed type is 'Union[__main__.B, None]' | |
| reveal_type(args) # N: Revealed type is 'builtins.tuple[__main__.C]' | |
| reveal_type(d) # N: Revealed type is 'Union[__main__.D, None]' | |
| reveal_type(e) # N: Revealed type is '__main__.E' | |
| reveal_type(kwargs) # N: 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) # N: Revealed type is '__main__.A' | |
| reveal_type(b) # N: Revealed type is 'Union[__main__.B, None]' | |
| reveal_type(args) # N: Revealed type is 'builtins.tuple[__main__.C]' | |
| reveal_type(d) # N: Revealed type is 'Union[__main__.D, None]' | |
| reveal_type(e) # N: Revealed type is '__main__.E' | |
| reveal_type(kwargs) # N: 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) # N: 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) # N: Revealed type is '__main__.A' | |
| reveal_type(b) # N: Revealed type is 'Union[__main__.B, None]' | |
| reveal_type(args) # N: 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) # N: Revealed type is '__main__.A' | |
| reveal_type(b) # N: Revealed type is 'Union[__main__.B, None]' | |
| reveal_type(args) # N: 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 | |
| f() | |
| f(1) # E: Too many arguments for "f" | |
| [case testFasterParseTooFewArgumentsAnnotation] | |
| def f(x, y): # E: Type signature has too few arguments | |
| # type: (int) -> None | |
| x() | |
| y() | |
| f(1, 2) | |
| f(1) # E: Too few arguments for "f" | |
| [case testFasterParseTooManyArgumentsAnnotation_python2] | |
| def f(): # E: Type signature has too many arguments | |
| # type: (int) -> None | |
| pass | |
| f() | |
| f(1) # E: Too many arguments for "f" | |
| [case testFasterParseTooFewArgumentsAnnotation_python2] | |
| def f(x, y): # E: Type signature has too few arguments | |
| # type: (int) -> None | |
| x() | |
| y() | |
| f(1, 2) | |
| f(1) # E: Too few arguments for "f" | |
| [case testFasterParseTypeCommentError_python2] | |
| from typing import Tuple | |
| def f(a): | |
| # type: (Tuple(int, int)) -> int | |
| pass | |
| [out] | |
| main:2: error: Invalid type comment or annotation | |
| main:2: note: Suggestion: use Tuple[...] instead of Tuple(...) | |
| [case testFasterParseTypeErrorList_python2] | |
| from typing import List | |
| def f(a): | |
| # type: (List(int)) -> int | |
| pass | |
| [builtins_py2 fixtures/floatdict_python2.pyi] | |
| [out] | |
| main:2: error: Invalid type comment or annotation | |
| main:2: 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) # E: Assertion is always true, perhaps remove parentheses? | |
| assert (1, 2), 3 # E: Assertion is always true, perhaps remove parentheses? | |
| assert () | |
| assert (1,) # E: 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 | |
| Bla().method() | |
| [file blamodule/backends/Bla.py] | |
| from .. import * | |
| class Bla: | |
| def method(self) -> str: | |
| return command.call() | |
| [file blamodule/command.py] | |
| def call() -> str: pass | |
| [builtins fixtures/module.pyi] | |
| [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? |