Discourage intermediate values for context managers#74
Discourage intermediate values for context managers#74
Conversation
Greptile SummaryThis PR adds a new section to
Confidence Score: 5/5Safe to merge — documentation-only change with one minor comment wording inaccuracy. The change is purely documentation (a Markdown style guide). The advice is technically sound, the code examples are valid Python, and the guidance is consistent with the rest of the file. The only issue found is a misleading inline comment in the second example, which has no runtime impact. No files require special attention beyond the minor comment wording fix flagged inline.
|
| Filename | Overview |
|---|---|
| skills/dignified-python/skills/dignified-python/dignified-python-core.md | Adds a new section discouraging extraction of context managers to intermediate variables; content is technically sound with one minor comment inaccuracy (second example labelled "Multiple conditional context managers" but only shows one). |
Sequence Diagram
sequenceDiagram
participant Code as User Code
participant CM as Context Manager
note over Code,CM: PREFERRED: Inline in with statement
Code->>CM: with (cm_a if cond else nullcontext())
CM->>CM: __enter__()
Code->>Code: do_work()
CM->>CM: __exit__()
note over Code,CM: DISCOURAGED: Extracted to intermediate variable
Code->>CM: cm = cm_a if cond else nullcontext()
Code->>CM: with cm:
CM->>CM: __enter__()
Code->>Code: do_work()
CM->>CM: __exit__()
Reviews (1): Last reviewed commit: "cp" | Re-trigger Greptile
| # CORRECT: Multiple conditional context managers | ||
| with (lock if thread_safe else nullcontext()): |
There was a problem hiding this comment.
The comment says "Multiple conditional context managers," but the example only shows a single conditional context manager (with a nullcontext() fallback). This could confuse readers into thinking the guidance applies specifically to multiple context managers rather than any conditional context manager.
| # CORRECT: Multiple conditional context managers | |
| with (lock if thread_safe else nullcontext()): | |
| # CORRECT: Conditional context manager with nullcontext fallback | |
| with (lock if thread_safe else nullcontext()): |

Summary & Motivation
Test Plan
Changelog