Skip to content

Define a LineWriter type for use in OutputWriter#2335

Open
sirosen wants to merge 1 commit intojazzband:mainfrom
sirosen:cleanup-dry-run-writer
Open

Define a LineWriter type for use in OutputWriter#2335
sirosen wants to merge 1 commit intojazzband:mainfrom
sirosen:cleanup-dry-run-writer

Conversation

@sirosen
Copy link
Member

@sirosen sirosen commented Feb 12, 2026

closes #1696

Hat tip to @graingert for the original! I'm just carrying it over the finish line.

Because this is primarily a readability edit of existing logic, I have not included a changelog or new tests. (Open to changing upon request/feedback.)


To abstract away the distinction between writing lines in dry-run mode
and non-dry-run mode, define a small protocol for a "line writer" which
takes and emits lines of text as strs.

This idea originates in #1696 , but was not completed at the time. On
review, the change is perfectly sound and can be implemented with some
slightly clearer types using a protocol to define the interface common to
the two codepaths.
The abstraction improves readability, especially by moving a finally
block into a context manager __exit__ function.

Contributor checklist
  • Included tests for the changes.
  • A change note is created in changelog.d/ (see changelog.d/README.md
    for instructions) or the PR text says "no changelog needed".
Maintainer checklist
  • If no changelog is needed, apply the bot:chronographer:skip label.
  • Assign the PR to an existing or new milestone for the target version
    (following Semantic Versioning).

To abstract away the distinction between writing lines in dry-run mode
and non-dry-run mode, define a small protocol for a "line writer" which
takes and emits lines of text as `str`s.

This idea originates in jazzband#1696 , but was not completed at the time. On
review, the change is perfectly sound and can be implemented with some
slightly clearer types using a protocol to define the interface common to
the two codepaths.
The abstraction improves readability, especially by moving a `finally`
block into a contextmanager `__exit__` function.

Co-authored-by: Thomas Grainger <413772+graingert@users.noreply.github.com>
@sirosen sirosen added this to the 7.5.4 milestone Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments