-
What and Why https://peps.python.org/pep-3107/ https://peps.python.org/pep-0484/
-
Life without types
-
Type Hints: Mypy, pycharm, VS Code
-
Type Hints are available in runtime (
inspect.get_annotations
)
-
Generic lists
- list[int], list[str], list[int|str|bool]
-
Generic Dictionaries
- dict[str, int], dict[Any, int]
-
TypedDict
- use only specific keys in dict
- Literal
- NotRequired
-
Simple input/output type hints def x(a: str, b: int) -> list[int]: pass
-
Typing *args
-
Typing **kwargs
-
Default args
-
Generator Functions
-
Warning: Type Hints and Built-in functions
-
Every class is a type
-
Protocols
-
Type Hints for Recursive Structures
class Node: value: int left: Node right: Node
def dfs(): pass
n = Node(10) n.right = Node(12) n.right.right = Node(15) n.right.left = Node(9) n.dfs()
-
Unsolved Identity Problem
-
Hello TypeVar
-
Hello ParamSpec
-
Types for Decorators
-
Built-in Type Guards
-
Creating Your Own Type Guard
-
casting
-
Creating type aliases
-
Defining new types with NewType