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

Fix warning due to line iterator __del__ #327

Merged
merged 1 commit into from
Jun 7, 2024

Conversation

tovrstra
Copy link
Member

@tovrstra tovrstra commented Jun 7, 2024

The fixed code caused warnings, essentially due to an antipattern. One should use context managers to clean up resources, instead of doing so in the __del__ method. See #313 for the bigger picture.

I'm planning to YOLO-merge this on Thursday, June 13 unless reviewed earlier.

Summary by Sourcery

This pull request addresses a warning related to resource cleanup by refactoring the LineIterator class to use a context manager instead of the __del__ method. The changes include updates to the class implementation, modifications to the usage in various parts of the codebase, and adjustments to the test cases to align with the new context manager approach.

  • Bug Fixes:
    • Fixed resource cleanup warning by replacing the use of __del__ method with context manager in LineIterator class.
  • Enhancements:
    • Refactored LineIterator class to be used as a context manager, improving resource management and code readability.
  • Tests:
    • Updated test cases to use the LineIterator class as a context manager, ensuring proper resource cleanup during tests.

Copy link
Contributor

sourcery-ai bot commented Jun 7, 2024

Reviewer's Guide by Sourcery

This pull request addresses a warning caused by the use of the __del__ method in the LineIterator class. The changes involve refactoring the LineIterator class to use context managers for resource cleanup, updating the usage of LineIterator across various files, and ensuring that the file handles are properly managed.

File-Level Changes

Files Changes
iodata/api.py
iodata/test/test_qchemlog.py
iodata/test/test_wfx.py
iodata/test/test_molden.py
iodata/test/test_wfn.py
Updated various functions and tests to use LineIterator as a context manager.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

deepsource-io bot commented Jun 7, 2024

Here's the code health analysis summary for commits 4437bbf..b1367f7. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Shell LogoShell✅ SuccessView Check ↗
DeepSource Python LogoPython✅ Success
🎯 1 occurence resolved
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @tovrstra - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 6 issues found
  • 🟡 Complexity: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

iodata/utils.py Show resolved Hide resolved
iodata/formats/json.py Show resolved Hide resolved
iodata/test/test_qchemlog.py Show resolved Hide resolved
iodata/test/test_wfx.py Show resolved Hide resolved
iodata/test/test_wfx.py Show resolved Hide resolved
iodata/test/test_molden.py Show resolved Hide resolved
iodata/test/test_wfn.py Show resolved Hide resolved
iodata/test/test_wfx.py Show resolved Hide resolved
iodata/utils.py Show resolved Hide resolved
Copy link
Member

@PaulWAyers PaulWAyers left a comment

Choose a reason for hiding this comment

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

Seems OK to me.

@tovrstra
Copy link
Member Author

tovrstra commented Jun 7, 2024

Thanks. Last one for today....

@tovrstra tovrstra merged commit c7a7469 into theochem:main Jun 7, 2024
10 checks passed
@tovrstra tovrstra deleted the warning-line-iterator branch June 7, 2024 18:10
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