Chapter 8

Small Objects, Records, and Type Hints

Objects, attributes, small classes, methods, dataclasses, function type hints, and configuration records.

Subject
Python
Lessons
6 lessons
Practice
11 checks
Review
3 pages

What this chapter does

Modern ML code often passes named bundles of settings and results. This chapter teaches just enough objects and type hints to read and write those records without turning object-oriented programming into a separate subject.

Lessons

Read these in order.

The chapter opening gives the main idea. Move through these lessons next; each page reuses ideas from the pages before it.

  1. 01
    Objects and Attributes

    Dot notation, attributes, methods on built-in values, and AttributeError.

  2. 02
    Small Classes

    Classes as object shapes, initializers, self, and when a class is useful.

  3. 03
    Methods

    Functions attached to objects and when behavior belongs near the data.

  4. 04
    Dataclasses

    Compact record definitions, field hints, generated initializers, and readable printed objects.

  5. 05
    Type Hints for Functions

    Parameter hints, return hints, simple container hints, and what hints do not enforce.

  6. 06
    Configuration Records

    Dataclasses for named experiment settings passed into small computations.

  1. Conclusion

    How small records prepare readers for array objects and experiment settings.

  2. Review

    A compact review of attributes, small classes, methods, dataclasses, type hints, and configuration records.

  3. Exercises

    Chapter-level practice for attributes, dataclasses, methods, type hints, and configuration records.

You are ready when

  • Read object attributes with dot notation.
  • Define a small class with an initializer.
  • Add a method when behavior belongs with the data.
  • Use dataclasses for simple records.
  • Read and write simple function type hints.
  • Pass a configuration record into a computation.

Where this leads

  • NumPy Arrays
  • Array Computation
  • Small Numerical Experiments

Chapter progress