typing
The typing module gives you names like Literal, Any or Callable to describe what kind of values your code expects.
Used in 35 lessons of the course, from 01.04.
typing is a standard library module. It holds tools for writing type hints that are more precise than int or str.
The line from typing import Literal brings only that name into your file. Then you use it in an annotation, for example mode: Literal["fast", "slow"].
Python does not check these annotations when it runs. They help your readers, your editor and tools like mypy, which flag mistakes before you run the code. Some libraries, like pydantic, do read them at runtime to validate data.
In the course you meet it from lesson 01.04, mostly with Literal, Any, Callable and TypedDict. Simple types like list[str] no longer need typing.
Reach for it when: a plain type hint is not enough: fixed allowed values, functions as arguments, or values of any type.
Examples
Common mistake
from typing import Literal
def paint(color: Literal["red", "blue"]) -> str:
return color
print(paint("green"))Why: Python does not enforce type hints at runtime, so "green" passes without error. Only a checker like mypy would flag it.
How to write it: Run a type checker, or validate with an if or a pydantic model if you need a real error.
Common mistake
print(Literal["a"])
Why: You used Literal without importing it. Names from typing are not available by default.
How to write it: Add from typing import Literal before using it.
