fix: Deterministically close file handles in the content linter - #77
Open
uditstocks wants to merge 1 commit into
Open
fix: Deterministically close file handles in the content linter#77uditstocks wants to merge 1 commit into
uditstocks wants to merge 1 commit into
Conversation
open(path).read() in check_file() left the file handle open, relying on
CPython refcount cleanup to close it. Wrap the read in a `with` block so
the handle is released deterministically, and use splitlines() in place
of split("\n").
✅ Deploy Preview for p2p-documentation ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
good fix on the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
check_file() in scripts/lint_content.py opened each content file with open(path, encoding="utf-8").read() and never closed the handle, relying on CPython's reference-counting to clean it up implicitly. This PR wraps the read in a with block so the handle is released deterministically, and switches to .splitlines() for cleaner line splitting.
Before
for lineno, line in enumerate(open(path, encoding="utf-8").read().split("\n"), 1):
After
with open(path, encoding="utf-8") as f:
lines = f.read().splitlines()
for lineno, line in enumerate(lines, 1):
Why this matters
Small change, but it removes a real class of fragility from CI-critical tooling:
Scope
No behavioral change to any lint rule; identical input produces identical output.
Touches a single function; the parsing and validation logic is unchanged.
Testing
Ran the linter locally against content/*.md; results are identical to main.