fbec36cb67
Scaffold the course repo and author the full curriculum in dependency-chain order, following the settled build decisions in handoff.md. - Scaffold: course README, vendor-neutral AGENTS.md (dogfoods Module 5), _TEMPLATE.md (the fixed 9-section module shape), root .gitignore, ship config. - Modules 1-2: reference exemplars (locked for tone/depth/lab style). - Modules 3-27: full lessons + runnable labs, each following the template, respecting the chain, vendor/model-agnostic, with "feel the pain" labs. - Module 8 hosting comparison web-researched and date-stamped (as of 2026-06-22), not written from memory; expansion-zone modules carry Verify-before-publish. - Capstone: the full loop end to end on the running tasks-app example. Lab code syntax-checked (Python/shell/YAML); every module has the 7 core template sections. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TfzV5QvtPDz8LJS3Pu5VLT
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""Core task logic for the demo app.
|
|
|
|
Same running example as Modules 1 and 2, with one addition: `complete` now validates the
|
|
index and raises a clear error for a bad one. That explicit edge-case handling is here on
|
|
purpose — it's the kind of thing an AI "refactor" likes to quietly remove. This is the
|
|
known-good base you'll review an AI change against in Module 10.
|
|
"""
|
|
|
|
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class Task:
|
|
title: str
|
|
done: bool = False
|
|
|
|
|
|
@dataclass
|
|
class TaskList:
|
|
tasks: list[Task] = field(default_factory=list)
|
|
|
|
def add(self, title: str) -> Task:
|
|
task = Task(title=title)
|
|
self.tasks.append(task)
|
|
return task
|
|
|
|
def complete(self, index: int) -> None:
|
|
if not 0 <= index < len(self.tasks):
|
|
raise IndexError(f"no task at index {index}")
|
|
self.tasks[index].done = True
|
|
|
|
def pending(self) -> list[Task]:
|
|
return [t for t in self.tasks if not t.done]
|
|
|
|
def render(self) -> str:
|
|
if not self.tasks:
|
|
return "(no tasks yet)"
|
|
lines = []
|
|
for i, task in enumerate(self.tasks):
|
|
box = "[x]" if task.done else "[ ]"
|
|
lines.append(f"{i}. {box} {task.title}")
|
|
return "\n".join(lines)
|