Part 4 · Section 09

Project 4

Time to put descriptors to work. In this project you’ll write the kind of field types that ORMs and validation libraries are built on: an IntegerField that only accepts integers within optional bounds, and a CharField that only accepts strings within optional length limits. Any class can then declare validated attributes in one line each.

Along the way you’ll write a proper unittest suite, discover a trap with __set_name__ when testing descriptors, create throwaway test classes with type(), use test-driven development to add a feature, and finally refactor the duplicated code into a base class, with the tests proving that nothing broke.

In this project you’ll:

Lectures

  1. 01Project 4 - Solution - Part 1✓
  2. 02Project 4 - Solution - Part 2✓

Practice: quiz & exercises

7 quiz questions · 4 coding exercises

Go to practice →