Skip to content
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

Refactor get_version to use a context manager for safe file handling #9669

Conversation

mahdirahimi1999
Copy link
Contributor

@mahdirahimi1999 mahdirahimi1999 commented Mar 26, 2025

Refactor get_version to use a context manager for safe file handling

This PR updates the get_version function to use a context manager (with open(...)) when reading the __init__.py file.

🔹 Key Improvements:

  • Ensures the file is properly closed after reading.
  • Improves code readability and maintainability.
  • Adds encoding='utf-8' for better compatibility across different systems.

This is a small but useful refactor to improve code reliability.

- Replaced open() and os.path.join() with Path.read_text() for simplicity and readability.
@mahdirahimi1999 mahdirahimi1999 force-pushed the fix/context-manager-get-version branch from 29b5b97 to f0e2746 Compare March 26, 2025 11:25
@mahdirahimi1999
Copy link
Contributor Author

Please check this PR. @tomchristie

@mahdirahimi1999
Copy link
Contributor Author

Hi @auvipy,
Will this PR be merged, or is there anything I should update? Thanks!

@mahdirahimi1999 mahdirahimi1999 requested a review from auvipy March 27, 2025 12:18
@tomchristie
Copy link
Member

Closing in line with eg. #9666 (comment)

In a different context it's a reasonable pull request. As it stands we're putting in place some clear boundaries to minimise unneccessary busy-work.

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.

5 participants