1from typing import Optional
2
3class Example:
4 required_field_1: str
5 required_field_2: int
6 optional_field: Optional[str]
1# Iterator
2def infinite_stream(start: int) -> Iterator[int]:
3 while True:
4 yield start
5 start += 1
6
7# Generator
8def infinite_stream(start: int) -> Generator[int, None, None]:
9 while True:
10 yield start
11 start += 1
12
1# For collections, the name of the type is capitalized, and the
2# name of the type inside the collection is in brackets
3x: List[int] = [1]
4x: Set[int] = {6, 7}
5
6# For simple built-in types, just use the name of the type
7x: int = 1
8x: float = 1.0
9x: bool = True
10x: str = "test"
11x: bytes = b"test"