This repository contains solutions for the exercises in Mastering Python,
Second Edition. Each solution_00.py is the maintained, typed reference
solution. Higher-numbered solution_NN.py files and specialized solution
files are community alternatives.
Development requires Python 3.10 or newer, uv, and Lefthook. On macOS, install the tools, synchronize every dependency group, and install the Git hooks:
$ brew install uv lefthook
$ uv sync --all-groups
$ lefthook installEach exercise_NN directory contains its exact question, a concise
explanation, the canonical answer in solution_00.py, its dependencies, and
focused tests. Run an answer or its tests from the repository root. For
example:
$ uv run python CH_04_design_patterns/exercise_01/solution_00.py
$ uv run pytest CH_04_design_patterns/exercise_01/test_solution_00.pyRun the complete formatting, linting, type-checking, and test suite before submitting changes:
$ uv run ruff format --check .
$ uv run ruff check .
$ uv run pyrefly check
$ uv run mypy .
$ uv run pyright
$ uv run pytestThe lockfile contains separate dependency groups so an exercise can use only the tools it needs:
dev- Documentation rendering, formatting, linting, type-checking, and tests.
interactive- Interactive Python, widgets, terminal colors, and completion support.
scientific- Numerical, tabular, notebook, and visualization tools.
nlp- Natural-language processing and its command-line support.
native- Native-extension build tools and C foreign-function interfaces.
packaging- Distribution builds, wheels, and isolated environment testing.
Install a single optional group when working only in that domain:
$ uv sync --group interactiveAfter the package cache has been populated, reproduce the complete locked environment without network access:
$ uv sync --all-groups --locked --offlineAlternative solutions are welcome and use the next available
solution_NN.py. Keep canonical files, tests, and exercise documentation
unchanged unless correcting the reference answer. All submitted Python code
must be formatted, linted, typed, and tested. Higher-numbered and specialized
community alternatives are intentionally excluded from automated canonical
gates to preserve historical files. New alternative pull requests must include
focused tests and report equivalent per-file Ruff, Pyrefly, mypy, and Pyright
results. The repository-wide commands above validate the maintained canonical
scope.