Type hints (PEP 484, Python 3.5+) không enforce lúc runtime nhưng mang lại:
- IDE autocompletion và refactoring tốt hơn
- Static analysis với mypy/pyright bắt lỗi trước runtime
- Documentation tự động — code tự giải thích
- Pydantic/FastAPI dùng type hints để validation
- Ít bugs hơn trong team lớn
Lưu ý: Type hints không prevent runtime errors — cần mypy --strict hoặc pyright trong CI pipeline.
Type hints do not enforce at runtime but provide:
- Better IDE autocompletion and refactoring
- Static analysis with mypy/pyright catches bugs early
- Self-documenting code
- Pydantic/FastAPI use them for validation
- Fewer bugs in large teams
Pitfall: Type hints do not prevent runtime errors — run mypy or pyright in CI.