Session M1-01 lab: Review inline suggestions¶
Duration: 2 hours
Difficulty: Beginner
Prerequisites: Python 3.10 or later
Deliverable: A completed and tested utils.py, the focused test suite, and a
decision record in lab-notes.md
Lab overview¶
You will complete one Python utility module in stages. The tests define the expected behavior. Inspect each proposed implementation and settle one ambiguous word-parsing rule. Then review a parameter rename as a separate change.
| 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 check the deliverable | 15 min |
Before you start¶
Use only synthetic data. Check that you may use the repository and editor for the exercise.
Before starting, check GitHub Copilot access in your editor. If it does not work, stop the lab. Manual implementation does not replace the inline-suggestion practice.
You need:
- Python 3.10 or later;
- a terminal;
- an editor;
- GitHub Copilot.
Part 1: Prepare the project (15 minutes)¶
Open the starter directory:
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 should pass. The five tests should fail because the functions do not return results yet.
Read utils.py, test_utils.py, change-request.md, and lab-notes.md. Do not
open the solution until the final comparison.
Checkpoint: You can name the expected result for every test before requesting a suggestion.
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 complete proposal before accepting it.
- Accept, revise, or reject it.
- Run:
Repeat the process for is_palindrome:
Record 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," you need to decide whether an apostrophe splits a word.
Read test_word_frequency_preserves_apostrophes. The accepted rule is:
Preserve an apostrophe when it appears inside a word.
don'tcounts as one word.
Use that decision to complete word_frequency. A simple split() or punctuation
removal may break the rule. If you cannot follow the proposed expression, ask
for an explanation before accepting it.
Run:
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 word-frequency tests pass, and the input string remains unchanged.
Part 4: Add the summary and apply the rename (30 minutes)¶
Complete profile_summary and run its focused test:
Now open change-request.md. Rename the first parameter from username to
handle.
If Next Edit Suggestions are available, review each predicted change separately. Do not assume every caller was found. Search after the rename:
The search should find no stale parameter or caller. Run the focused test again.
Checkpoint: The rename changed the parameter and caller without changing the output.
Part 5: Review and check (15 minutes)¶
Inspect the complete change:
If the working tree contains other changes, review only the three lab files.
Final deliverable¶
utils.pyimplements all four functions.test_utils.pypasses all five tests.lab-notes.mdrecords the access path, suggestion decisions, ambiguity decision, rename search, and final test result.
Verification¶
-
python -m py_compile utils.py test_utils.pysucceeds. -
python -m unittest -vpasses five tests. -
grep -R --include='*.py' "username" .finds no stale parameter or caller. - No dependency or unrelated file was added.
- The final diff matches the stated behavior.