Files
ai-workflow-course/modules/02-version-control-as-a-safety-net/lab/start/tasks.py
T
claude 07182429c4
CI / check (pull_request) Successful in 7s
feat(labs): make every lab a self-contained, skip-friendly starting point
Each lab now stands on its own; no hard dependency on prior labs.
- App-based labs get a canonical tasks-app snapshot in lab/start/ (three
  baselines: v0 add/list/done; v1 +count; v2 +count/delete), assigned by where
  each module sits in the command timeline. Modules with a purpose-built app
  (M10 trap, M13 planted bug, M21) snapshot their own app; planted devices kept.
- Self-contained labs (M15/17/18/19/22/23/24/25/27, which operate on their own
  lab files) get a preamble pointing at modules/NN/lab/.
- Every module + capstone gets a "Starting point (skip-friendly)" preamble:
  copy the snapshot, git init -b main, commit -> clean status, then start.

Lets a learner skip around or recover: copy start/, commit, go. All snapshots
run; tools/check.sh passes; no em-dashes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TfzV5QvtPDz8LJS3Pu5VLT
2026-06-23 18:24:17 -04:00

40 lines
1017 B
Python

"""Core task logic for the demo app.
Deliberately small and deliberately split across two files (this and cli.py) so that the
copy-paste workflow has more than one place to go wrong. This is the running example used in
Modules 1 and 2.
"""
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:
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)