promptdojo_

@dataclass — the class shape AI ships in every modern Python project — step 9 of 9

Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Last drill. Build two dataclasses that fit together:

  1. Address — a frozen=True dataclass with two fields:

    • street: str
    • city: str
  2. Customer — a regular @dataclass with three fields:

    • name: str
    • address: Address (a nested dataclass — required)
    • orders: list defaulting to field(default_factory=list)

Then create two customers sharing the same address (an Address is immutable, so sharing is fine), append an order to each, and print both.

Expected output:

Customer(name='maya', address=Address(street='1 main st', city='oak'), orders=['#1'])
Customer(name='marcus', address=Address(street='1 main st', city='oak'), orders=['#2'])

full-screen editor opens — close anytime to keep reading.