New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test, contrib, refactor: use with
when opening a file
#24993
Conversation
You're right, though prefer fixing this by using |
@laanwj, I didn't do it before because since in other places it closes the file after manipulating it (without using |
Concept ACK on identifying further such cases and fixing them. Especially for small scripts not closing is not a big deal in practice though; here is a nice list of arguments why it it strongly recommended to do it anyway: https://stackoverflow.com/a/25070939 Assuming that the following used regex is reliable, we have 17 occurences of
|
Sounds good to me. It removes the burden of having the explicitly think about closing (removes the entire bug class of "forget to close") so is very much preferred when it's possible. |
81fa5e0
to
bc6f939
Compare
linearize-data
bc6f939
to
2f287ad
Compare
2f287ad
to
027aab6
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
with
when opening a file
I think we could put in the docs a recommendation to use |
Code review ACK 027aab6
Not sure. Isn't that like a general Python thing, not specific to our project? I don't think it's worthwhile to maintain a document of basic Python programming language best practices in our project. |
… a file 027aab6 test, contrib, refactor: use `with` when opening a file (brunoerg) Pull request description: When manipulating a file in Python without using `with()`, you have to close the file manually, so this PR does it in `get_block_hashes` (`contrib/linearize/linearize-data.py`). Edit: this PR does it for all occurances that previously weren't using `with`. ACKs for top commit: laanwj: Code review ACK 027aab6 Tree-SHA512: 879400968e0013e8678ec16f1fe5d0963a73c1e0d442ca34802d885214f0783d2e9a9b500fc6be7c3b93560a367b6a3d685eee24d2f9ce53fddf064ea6feecf8
When manipulating a file in Python without using
with()
, you have to close the file manually, so this PR does it inget_block_hashes
(contrib/linearize/linearize-data.py
).Edit: this PR does it for all occurances that previously weren't using
with
.