Docstrings, comments & types
Writing documentation that lives in the code: docstring conventions from PEP 257, comments that help the next reader, and type hints from PEP 484 onwards.
- Python Docstrings: PEP 257 Conventions, Formats and Tools
How to write Python docstrings following PEP 257: one-line and multi-line docstrings, what to document for modules, classes and functions, the reST, Google and NumPy formats, doctest, and checking docstrings with ruff or pydocstyle.
- Python Type Hints: From PEP 484 to Modern Syntax, with Style Rules
A practical introduction to Python type hints: what annotations do and do not do at runtime, the syntax from PEP 484 to list[int], X | None and PEP 695 generics, how to format annotations, and how type checkers such as mypy use them.
- Writing Useful Comments in Python: What PEP 8 Says and What Helps Readers
How to write Python comments that help: PEP 8's rules for block and inline comments, explaining why rather than what, TODOs, commented-out code, tool directives such as noqa and type: ignore, and how comments differ from docstrings.
- mypy and Pyright: Choosing and Configuring a Python Type Checker
How the two main Python type checkers differ: what mypy and Pyright check by default, how they treat unannotated code, how to configure both in pyproject.toml, strict mode per module, ignore comments with error codes, and stubs for third-party libraries.



