-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
gh-131807: fix ResourceWarning in test_ucn.py #131808
Conversation
graingert
commented
Mar 27, 2025
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: ResourceWarning in test.test_ucn.UnicodeNamesTest.test_named_sequences_full (when http request 404s) #131807
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a ResourceWarning in test_ucn.py by adjusting how network resource errors are handled during URL retrieval in tests.
- Introduces an explicit import for urllib.error.
- Splits exception handling into a specific block for urllib.error.HTTPError (with an explicit resource cleanup) and a combined block for OSError and HTTPException.
- Replaces the previous cleanup approach with a context manager for test data.
Comments suppressed due to low confidence (2)
Lib/test/test_ucn.py:185
- Ensure that calling e.close() on HTTPError is valid and necessary; if HTTPError does not implement a close() method or is already handled by a context manager, this call might be redundant or could lead to unexpected behavior.
except urllib.error.HTTPError as e:
Lib/test/test_ucn.py:187
- [nitpick] Consider using a more concise error message format without variable name expansion (e.g. using '{e}' instead of '{e=}') to prevent potentially exposing internal details.
self.skipTest(f"Could not retrieve {url} {e=}")
Co-authored-by: Victor Stinner <vstinner@python.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @graingert for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
(cherry picked from commit adb67ed) Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
GH-131845 is a backport of this pull request to the 3.13 branch. |
(cherry picked from commit adb67ed) Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
GH-131846 is a backport of this pull request to the 3.12 branch. |
Merged, thanks for the fix. |
|
|