Skip to content

Add context manager lesson to usethis-python-code skill#1787

Merged
nathanjmcdougall merged 2 commits into
mainfrom
copilot/refactor-backup-restore-logic
Apr 3, 2026
Merged

Add context manager lesson to usethis-python-code skill#1787
nathanjmcdougall merged 2 commits into
mainfrom
copilot/refactor-backup-restore-logic

Conversation

Copilot AI commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Documents the lesson from #1786: prefer @contextmanager over paired backup/restore helpers for setup/teardown logic.

  • Added new "Preferring context managers for resource cleanup" section to usethis-python-code skill (v1.4 → v1.5)
  • Includes procedure, key principle, before/after example, and common mistakes — matching existing section structure
# Bad: caller manages lifecycle
backup = _backup(lock_path)
try:
    run_subprocess()
finally:
    _restore(lock_path, backup)

# Good: context manager encapsulates it
with _preserved(lock_path):
    run_subprocess()

Skills used: usethis-skills-modify, usethis-qa-static-checks

Document lesson: prefer @contextmanager over paired backup/restore
helpers for setup/teardown logic. Resolves #1786.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/39c28f2d-0309-4d9b-9654-2af0ec2a3c4b

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor to use context managers for backup and restore Add context manager lesson to usethis-python-code skill Apr 3, 2026
Copilot AI requested a review from nathanjmcdougall April 3, 2026 21:17
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review April 3, 2026 21:18
@nathanjmcdougall nathanjmcdougall merged commit 9a86da5 into main Apr 3, 2026
1 check passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/refactor-backup-restore-logic branch April 3, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lesson: prefer context managers over paired backup/restore helpers

2 participants