You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .agents/skills/usethis-python-code/SKILL.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: Guidelines for Python code design decisions such as when to share v
4
4
compatibility: usethis, Python
5
5
license: MIT
6
6
metadata:
7
-
version: "1.8"
7
+
version: "1.9"
8
8
---
9
9
10
10
# Python Code Guidelines
@@ -165,6 +165,7 @@ with _preserved(lock_path):
165
165
166
166
-**Separate backup and restore helpers.** Splitting setup and teardown into two functions forces every caller to remember both calls and wire up `try`/`finally` correctly. A context manager removes this burden.
167
167
-**Forgetting `finally` in the caller.** Without a context manager, it is easy to forget the `finally` block, leaving state unrestored if an exception occurs. A context manager guarantees cleanup.
168
+
-**Placing cleanup after `yield` without `try`/`finally` in a `@contextmanager`.** With `@contextmanager`, cleanup code placed after `yield` does NOT run if an exception is raised inside the `with` block. The exception is re-raised at the `yield` point, causing the generator to terminate without reaching the cleanup code. Always wrap `yield` in `try`/`finally` to guarantee cleanup runs on both normal exit and exceptions.
0 commit comments