| -- Type checking after an error during semantic analysis |
| -- ----------------------------------------------------- |
| -- |
| -- This tests both the semantic analyzer (that it does not generate |
| -- corrupt state on error) and the type checker (that it can deal with |
| -- whatever state the semantic analyzer sets up). |
| |
| -- TODO: |
| -- - invalid type in annotation |
| -- - invalid function comment type annotation |
| -- - invalid multiple assignment type annotation |
| -- - using a type variable as a value |
| -- - using special names defined in typing as values |
| |
| [case testMissingModuleImport1] |
| import m # E |
| m.foo() |
| m.x = m.y |
| 1() # E |
| [out] |
| main:1: error: Cannot find module named 'm' |
| main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) |
| main:4: error: "int" not callable |
| |
| [case testMissingModuleImport2] |
| from m import x # E |
| x.foo() |
| x.a = x.b |
| 1() # E |
| [out] |
| main:1: error: Cannot find module named 'm' |
| main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) |
| main:4: error: "int" not callable |
| |
| [case testMissingModuleImport3] |
| from m import * # E |
| x # E |
| 1() # E |
| [out] |
| main:1: error: Cannot find module named 'm' |
| main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) |
| main:2: error: Name 'x' is not defined |
| main:3: error: "int" not callable |
| |
| [case testInvalidBaseClass1] |
| class A(X): # E: Name 'X' is not defined |
| x = 1 |
| A().foo(1) |
| A().x = '' # E: Incompatible types in assignment (expression has type "str", variable has type "int") |
| |
| [case testInvalidBaseClass2] |
| X = 1 |
| class A(X): # E |
| x = 1 |
| A().foo(1) |
| A().x = '' # E |
| [out] |
| main:2: error: Invalid type "__main__.X" |
| main:2: error: Invalid base class |
| main:5: error: Incompatible types in assignment (expression has type "str", variable has type "int") |
| |
| |
| [case testInvalidNumberOfTypeArgs] |
| from typing import TypeVar |
| T = TypeVar('T') |
| class C: # Forgot to add type params here |
| def __init__(self, t: T) -> None: pass |
| c = C(t=3) # type: C[int] # E: "C" expects no type arguments, but 1 given |
| |
| [case testBreakOutsideLoop] |
| break # E: 'break' outside loop |
| |
| [case testContinueOutsideLoop] |
| continue # E: 'continue' outside loop |
| |
| [case testYieldOutsideFunction] |
| yield # E: 'yield' outside function |
| |
| [case testYieldFromOutsideFunction] |
| x = 1 |
| yield from x # E: 'yield from' outside function |