Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #166 +/- ##
==========================================
+ Coverage 93.85% 96.76% +2.91%
==========================================
Files 3 3
Lines 374 557 +183
Branches 29 36 +7
==========================================
+ Hits 351 539 +188
+ Misses 14 10 -4
+ Partials 9 8 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR introduces explicit resource cleanup to DNSResolver by adding a close() method, async context manager support, and an improved __del__ for automatic cleanup. It also updates tests to cover the new functionality, bumps the minimum pycares dependency, and updates the documentation.
- Add
_cleanup(),async close(),__aenter__/__aexit__, and enhanced__del__inDNSResolver - Extend test suite with close, idempotence, destructor, and context‐manager tests
- Bump
pycaresrequirement to>=4.9.0and document the new API
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_aiodns.py | New tests for close(), context manager, and __del__ cleanup; updated tearDown to call close() |
| setup.py | Updated pycares minimum version in install_requires |
| aiodns/init.py | Implemented _cleanup(), close(), async context manager, and refined destructor behavior |
| README.rst | Documented close() method and async context manager usage |
Comments suppressed due to low confidence (2)
setup.py:24
- Bumping the minimum
pycaresversion to 4.9.0 may affect users upgrading from older versions. Ensure this change is documented in the changelog and migration notes.
install_requires=['pycares>=4.9.0'],
aiodns/init.py:369
- [nitpick] In
__del__, calling_cleanup()may raise if the loop or channel state is invalid. Wrap the call intry/exceptto suppress exceptions during garbage collection.
def __del__(self) -> None:
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Thanks. I'll see if I can do a release before lunch |
What do these changes do?
This PR adds a
close()method to theDNSResolverclass to allow for explicit cleanup of resources. The implementation includes:close()method that cleanly shuts down the resolver by canceling timers, removing file descriptors, and closing the pycares channel__aenter__and__aexit__) for automatic cleanup when usingasync with__del__method that automatically calls cleanup when the resolver is garbage collectedAre there changes in behavior for the user?
await resolver.close()async with aiodns.DNSResolver() as resolver:Related issue number
Fixes #165
Checklist