Skip to content

wrap file open in a with statement#61

Merged
jwaiton merged 1 commit intonu-ZOO:mainfrom
mmillns2:safe_file_open
Feb 3, 2026
Merged

wrap file open in a with statement#61
jwaiton merged 1 commit intonu-ZOO:mainfrom
mmillns2:safe_file_open

Conversation

@mmillns2
Copy link
Member

@mmillns2 mmillns2 commented Feb 3, 2026

This PR addresses issue #54: Inappropriate file opening

  • This PR wraps a file open in a with statement.

Implementation

  • Previously we had something like:
file = open(file_path, 'rb')
...
file.close()
  • The issue with this is that if for some reason the code breaks between the open and close, the file remains open. This is unsafe.

  • To make this safe, a with statement can be used to ensure correct file closing:

with open(file_path, 'rb') as file:
    ...

@mmillns2 mmillns2 requested a review from a team February 3, 2026 14:00
Copy link
Member

@jwaiton jwaiton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR resolves an unsafe implementation of file opening, good work!

@jwaiton jwaiton merged commit 51bb8f4 into nu-ZOO:main Feb 3, 2026
1 check passed
@jwaiton jwaiton mentioned this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants