[case testNewSyntaxRequire36]
# flags: --python-version 3.5
x: int = 5  # E: Variable annotation syntax is only supported in Python 3.6 and greater
[out]

[case testNewSyntaxSyntaxError]
# flags: --python-version 3.6
x: int: int  # E: invalid syntax
[out]

[case testNewSyntaxBasics]
# flags: --python-version 3.6
x: int
x = 5
y: int = 5

a: str
a = 5  # E: Incompatible types in assignment (expression has type "int", variable has type "str")
b: str = 5  # E: Incompatible types in assignment (expression has type "int", variable has type "str")

zzz: int
zzz: str  # E: Name 'zzz' already defined on line 10
[out]

[case testNewSyntaxWithDict]
# flags: --python-version 3.6
from typing import Dict, Any

d: Dict[int, str] = {}
d[42] = 'ab'
d[42] = 42  # E: Incompatible types in assignment (expression has type "int", target has type "str")
d['ab'] = 'ab'  # E: Invalid index type "str" for "Dict[int, str]"; expected type "int"
[builtins fixtures/dict.pyi]
[out]

[case testNewSyntaxWithRevealType]
# flags: --python-version 3.6
from typing import Dict

def tst_local(dct: Dict[int, T]) -> Dict[T, int]:
    ret: Dict[T, int] = {}
    return ret

reveal_type(tst_local({1: 'a'}))  # E: Revealed type is 'builtins.dict[builtins.str*, builtins.int]'
[builtins fixtures/dict.pyi]
[out]

[case testNewSyntaxWithInstanceVars]
# flags: --python-version 3.6
class TstInstance:
    a: str
    def __init__(self) -> None:
        self.x: int

TstInstance().x = 5
TstInstance().x = 'ab'  # E: Incompatible types in assignment (expression has type "str", variable has type "int")
TstInstance().a = 5  # E: Incompatible types in assignment (expression has type "int", variable has type "str")
TstInstance().a = 'ab'
[out]

[case testNewSyntaxWithClassVars]
# flags: --strict-optional --python-version 3.6
class CCC:
    a: str = None  # E: Incompatible types in assignment (expression has type "None", variable has type "str")
[out]

[case testNewSyntaxWithStrictOptional]
# flags: --strict-optional --python-version 3.6
strict: int
strict = None  # E: Incompatible types in assignment (expression has type "None", variable has type "int")
strict2: int = None  # E: Incompatible types in assignment (expression has type "None", variable has type "int")
[out]

[case testNewSyntaxWithStrictOptionalFunctions]
# flags: --strict-optional --python-version 3.6
def f() -> None:
    x: int
    x = None  # E: Incompatible types in assignment (expression has type "None", variable has type "int")
[out]

[case testNewSyntaxWithStrictOptionalClasses]
# flags: --strict-optional --python-version 3.6
class C:
    def meth(self) -> None:
        x: int = None  # E: Incompatible types in assignment (expression has type "None", variable has type "int")
        self.x: int = None  # E: Incompatible types in assignment (expression has type "None", variable has type "int")
[out]

[case testNewSyntaxSpecialAssign]
# flags: --python-version 3.6
class X:
    x: str
    x[0]: int
    x.x: int

[out]
main:4: error: Unexpected type declaration
main:4: error: Unsupported target for indexed assignment
main:5: error: Type cannot be declared in assignment to non-self attribute
main:5: error: "str" has no attribute "x"

[case testNewSyntaxAsyncComprehensionError]
# flags: --python-version 3.5
async def f():
    results = [i async for i in aiter() if i % 2]  # E: Async comprehensions are only supported in Python 3.6 and greater


[case testNewSyntaxFstringError]
# flags: --python-version 3.5
f''  # E: Format strings are only supported in Python 3.6 and greater

[case testNewSyntaxFStringBasics]
# flags: --python-version 3.6
f'foobar'
f'{"foobar"}'
f'foo{"bar"}'
f'.{1}.'
f'{type(1)}'
a: str
a = f'foobar'
a = f'{"foobar"}'
[builtins fixtures/f_string.pyi]

[case testNewSyntaxFStringExpressionsOk]
# flags: --python-version 3.6
f'.{1 + 1}.'
f'.{1 + 1}.{"foo" + "bar"}'
[builtins fixtures/f_string.pyi]

[case testNewSyntaxFStringExpressionsErrors]
# flags: --python-version 3.6
f'{1 + ""}'
f'.{1 + ""}'
[builtins fixtures/f_string.pyi]
[out]
main:2: error: Unsupported operand types for + ("int" and "str")
main:3: error: Unsupported operand types for + ("int" and "str")

[case testNewSyntaxFStringParseFormatOptions]
# flags: --python-version 3.6
value = 10.5142
width = 10
precision = 4
f'result: {value:{width}.{precision}}'
[builtins fixtures/f_string.pyi]

[case testNewSyntaxFStringSingleField]
# flags: --python-version 3.6
v = 1
reveal_type(f'{v}') # E: Revealed type is 'builtins.str'
reveal_type(f'{1}') # E: Revealed type is 'builtins.str'
[builtins fixtures/f_string.pyi]

