Session M1-01 lab: Review inline suggestions¶
Duration: 2 hours
Deliverable: A completed and tested utils.py, the focused test suite, and
your notes in lab-notes.md
Lab overview¶
You complete one Python utility module in stages. The tests define the expected behavior. Inspect each suggestion, settle one ambiguous word-parsing rule, then rename a parameter. Use synthetic data only.
| Part | Work | Time |
|---|---|---|
| 1 | Prepare the project and inspect the failing baseline | 15 min |
| 2 | Complete two functions | 30 min |
| 3 | Resolve the word-parsing ambiguity | 30 min |
| 4 | Add the profile summary and apply the rename | 30 min |
| 5 | Review the diff and run all tests | 15 min |
You need Python 3.10 or later, a terminal, an editor with GitHub Copilot, and
git. Writing the code by hand skips the inline-suggestion practice.
Part 1: Prepare the project (15 minutes)¶
cd sessions/session-m1-01-intro-to-copilot/lab/starter
python -m py_compile utils.py test_utils.py
python -m unittest -v
The syntax check passes. The five tests fail because the functions return nothing yet.
Read utils.py, test_utils.py, change-request.md, and lab-notes.md. Keep
the solution closed until the final comparison.
Checkpoint: You can name the expected result for every test.
Part 2: Complete two functions (30 minutes)¶
Start with normalize_username.
- Read its docstring and focused test.
- Place the cursor in the function body.
- Request or wait for an inline suggestion.
- Read the whole suggestion, then accept, revise, or reject it.
- Run:
Repeat for is_palindrome:
Note both decisions in lab-notes.md.
Checkpoint: Two focused tests pass. The module has no new dependency.
Part 3: Resolve the word-parsing ambiguity (30 minutes)¶
Before implementing "count words," decide whether an apostrophe splits a word.
Read test_word_frequency_preserves_apostrophes. The rule is:
Keep an apostrophe inside a word.
don'tcounts as one word.
Complete word_frequency with that rule. A plain split() or punctuation
removal can break it. If you can't follow a suggested expression, ask Copilot to
explain it before you accept it.
python -m unittest -v \
test_utils.UtilityTests.test_word_frequency_preserves_apostrophes \
test_utils.UtilityTests.test_word_frequency_does_not_change_input
Update the ambiguity section in lab-notes.md.
Checkpoint: Both tests pass, and the input string stays unchanged.
Part 4: Add the summary and apply the rename (30 minutes)¶
Complete profile_summary, then run its test:
Open change-request.md and rename the first parameter from username to
handle.
If Next Edit Suggestions are available, review each proposed change. Then search for the old name and run the test again:
Checkpoint: The search finds no stale username, and the test passes.
Part 5: Review the diff (15 minutes)¶
If the working tree has other changes, review only these three files.
Final deliverable¶
utils.pyimplements all four functions.test_utils.pypasses all five tests.lab-notes.mdrecords your suggestion decisions, the apostrophe decision, the rename search, and the final test result.