Prerequisites & Notation
Before You Begin
This chapter builds on core Python fluency from Chapters 1-3. You should be comfortable writing classes, decorators, and closures before adding type annotations, tests, and packaging around them.
- Functions, closures, and decorators (Chapter 2)(Review ch02)
Self-check: Can you write a decorator that logs function call arguments and return values?
- Classes, dataclasses, and Protocols (Chapter 3)(Review ch03)
Self-check: Can you define a Protocol with two abstract methods and verify a class satisfies it?
- NumPy array basics: shapes, dtypes, broadcasting
Self-check: Can you create a (3, 4) array and broadcast-add a (4,) vector to it?
- Command-line Python: running scripts, installing packages(Review ch01)
Self-check: Can you run
pip install pytestin a virtual environment and executepytestfrom the terminal?
Notation for This Chapter
Symbols and conventions introduced in this chapter for type annotations, testing, and project structure.
| Symbol | Meaning | Introduced |
|---|---|---|
Generic type variable, bound via TypeVar('T') | s01 | |
Union type (Python 3.10+ syntax), equivalent to Optional[X] | s01 | |
Runtime assertion statement β disabled when Python runs with -O flag | s02 | |
| Decorator marking a function as a test fixture (setup/teardown) | s03 | |
| Decorator that generates multiple test cases from parameter lists | s03 | |
| Built-in function that drops into the debugger (PEP 553) | s04 | |
| Unified Python project configuration file (PEP 518, PEP 621) | s05 |