from typing import Any
- a = None # type: Any
- a = [] # OK
- a = 2 # OK
+ a: Any = None
+ a = [] # OK
+ a = 2 # OK
- s = '' # type: str
- s = a # OK
+ s = '' # Inferred type of 's' is str
+ s = a # OK
def foo(item: Any) -> int:
# Typechecks; 'item' could be any type,
correspond to those of :class:`Generator`, for example::
from collections.abc import Coroutine
- c = None # type: Coroutine[list[str], str, int]
- ...
- x = c.send('hi') # type: list[str]
+ c: Coroutine[list[str], str, int] # Some coroutine defined elsewhere
+ x = c.send('hi') # Inferred type of 'x' is list[str]
async def bar() -> None:
- x = await c # type: int
+ y = await c # Inferred type of 'y' is int
.. versionadded:: 3.5.3