Python Modules 00-10
ProjectM2
Eleven Python modules from basics and data handling to abstract classes, packages, patterns, Pydantic and functional style, checked with flake8 and mypy.
Requires
Unlocks
Guide
Python Modules is the milestone M2 bridge from C to Python, done solo: eleven short modules, numbered 00 to 10, each a set of small exercises around one theme, validated one after the other. They take you from print and loops to classes, packages, virtual environments, Pydantic and functional programming, all under strict typing. Every later Python project in the core (A-Maze-ing, Call Me Maybe, Fly-in, Pac-Man, RAG against the machine, Agent Smith) assumes you finished them properly. Module titles and exercise details come from student repositories (Reported by students) and may differ between subject versions.
What you will learn
- Writing idiomatic Python 3.10+ with type hints on every function
- Passing
flake8andmypy(andmypy --strict) as a habit, not a final step - Object-oriented design: classes, inheritance, abstract classes, protocols, design patterns
- Exceptions, files, packages and imports, virtual environments and dependency management
- Data validation with Pydantic v2 and functional tools (closures, decorators,
functools)
The modules, one line each (titles Reported by students):
- 00 Growing Code:
print,input, conditions, loops, recursion, type hints and the__name__guard, in a garden theme. - 01 Code Cultivation: classes, encapsulation, inheritance, static and class methods, a simple factory.
- 02 Garden Guardian:
try,except,finally,raiseand your own exception hierarchy. - 03 Data Quest: lists, tuples, sets, dicts, comprehensions, generators and
sys.argv. - 04 Data Archivist: reading and writing files,
with, line by line versus whole file, stdin, stdout and stderr. - 05 Code Nexus: abstract base classes, overriding,
Protocoland polymorphic data pipelines. - 06 The Codex: packages,
__init__.py,__all__, absolute and relative imports, avoiding circular imports. - 07 DataDeck: a card game built with abstract factory, mixins and the strategy pattern.
- 08 The Matrix:
venv,pip, Poetry andpyproject.toml,.envfiles and a clean.gitignore. - 09 Cosmic Data: Pydantic v2 models,
Fieldconstraints, validators and nested models. - 10 FuncMage: lambdas, higher-order functions, closures, decorators,
functools.reduceandlru_cache.
Before you start
- Previous nodes: Libft and the M1 projects. You do not need Python experience, but you need the C habits: read the subject twice, test edge cases.
- Tools: Python 3.10 or newer,
flake8,mypy, and a virtual environment per module (python3 -m venv .venv). - Configure your editor to run flake8 and mypy on save.
- Read the official Python tutorial up to classes before module 01.
Plan of attack
- Set up once: a template folder with a
.venv, a requirements file containingflake8andmypy, and a Makefile withlintandlint-stricttargets you copy into every module. - Modules 00 and 01 (two to three days): module 01 is the foundation of everything after it; students report it takes the longest. Do not rush the class design.
- Modules 02 to 04 (two days): write each exception class and file helper with full annotations; test the failure paths, not just the happy path.
- Modules 05 to 07 (three days): sketch the class diagram on paper before coding. Abstract classes must really be abstract (
ABCplusabstractmethod). - Module 08 (one day): create the environment from scratch twice, once with
venvpluspip, once with Poetry, and explain the difference. - Modules 09 and 10 (two days): read the Pydantic v2 docs, not v1 tutorials; write decorators that keep the wrapped function's signature with
functools.wraps. - Before each evaluation: run
make lint-strict, delete__pycache__and the venv from the repository, and reread the README.
lint:
flake8 .
mypy .
lint-strict:
flake8 .
mypy --strict .
Common pitfalls
- A single flake8 or mypy error fails the exercise;
mypy --strictrejects missing return types and untypeddef. - Files that run code at import time instead of exposing functions (exercises are often imported by the grader).
- Wrong file or function names: the grader looks for exact names.
- Using Pydantic v1 syntax (
validator,class Config) in module 09. - Committing
.venv,__pycache__or.envfiles. - Ambiguous statements (students mention module 05): ask peers and keep a note of your interpretation in the README.
How it is evaluated
- Each module is a separate project with its own peer evaluation. The evaluator runs flake8 and mypy first; any warning stops the evaluation.
- Then each exercise is run with normal and edge inputs and compared with the expected output.
- You explain your design choices: why a class is abstract, why a pattern fits, how imports resolve.
- READMEs with a section on how AI was used are expected (Reported by students).
- A Python tester for module 00 exists but is archived; most checking is manual.