Type Hints and Clean Code
Write Python other developers are glad to read and maintain.
Write code the way a reviewer wants to read it. You will annotate functions with type hints (collections, None, Callable, Iterable, TypedDict, Protocol and Literal), follow PEP 8 naming and layout, and refactor with tests holding behavior steady: extract functions, flatten nesting with early returns, name magic numbers and remove flag arguments. The course ends by untangling a messy script into typed, documented, tested functions.
What you will learn
- Type hints
- TypedDict, Protocol and Literal
- PEP 8 and naming
- Refactoring
- Early returns
- Google-style docstrings
Lessons
- 1
Type Hints
Annotate parameters and return values, describe collections and None, and learn what hints do and do not do.
8 exercises
- 2
Richer Types
Hint functions you pass around, accept any iterable, and describe dict records, fixed choices and duck-typed objects.
7 exercises
- 3
PEP 8 and Naming
Follow the conventions every Python team expects, choose names that explain themselves, and let tools handle formatting.
8 exercises
- 4
Refactoring
Improve the structure of working code without changing what it does: extract functions, flatten nesting, name numbers and remove flag arguments.
8 exercises
- 5
Putting It Together
Document functions in Google style, then turn tangled code into typed, named, tested functions.
3 exercises
How you practice
You practice in the browser and every exercise gives you feedback right away. This course uses these formats:
- Code exercise: 15
- Multiple choice: 5
- Fix the bug: 4
- Predict the output: 2
- Match the pairs: 2
- Spot the bug: 2
- Fill in the blank: 1
- Select all that apply: 1
- Type the answer: 1
- Reorder lines: 1
Aligned to
- Software Development Fundamentals
- SDF-PracticesSoftware Development Practices
Proto Node Labs is not affiliated with or endorsed by ACM / IEEE-CS / AAAI. Exam names are trademarks of their owners.