classes — reading what ai just wrote you8 / 9
@dataclass — the class shape ai ships in every modern python project
Write a Task dataclass with three fields:
title: str(required)priority: intwith default1tags: listwithfield(default_factory=list)
Use the @dataclass decorator. Don't write __init__ by hand —
let the decorator generate it.
Then create two tasks, append a tag to one of them, and print both to verify the lists are independent.
Expected output:
Task(title='ship', priority=1, tags=['urgent'])
Task(title='clean inbox', priority=3, tags=[])
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _