File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change
1
+ Fixed :py:class: `~aiohttp.resolver.AsyncResolver ` not using the ``loop `` argument in versions 3.x where it should still be supported -- by :user: `bdraco `.
Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ def __init__(
94
94
if aiodns is None :
95
95
raise RuntimeError ("Resolver requires aiodns library" )
96
96
97
- self ._loop = asyncio .get_running_loop ()
97
+ self ._loop = loop or asyncio .get_running_loop ()
98
98
self ._manager : Optional [_DNSResolverManager ] = None
99
99
# If custom args are provided, create a dedicated resolver instance
100
100
# This means each AsyncResolver with custom args gets its own
Original file line number Diff line number Diff line change @@ -711,3 +711,37 @@ async def test_async_resolver_close_with_none_resolver() -> None:
711
711
712
712
# This should not raise AttributeError
713
713
await resolver .close ()
714
+
715
+
716
+ @pytest .mark .skipif (aiodns is None , reason = "aiodns required" )
717
+ def test_async_resolver_uses_provided_loop () -> None :
718
+ """Test that AsyncResolver uses the loop parameter when provided."""
719
+ # Create a custom event loop
720
+ custom_loop = asyncio .new_event_loop ()
721
+
722
+ try :
723
+ # Need to set the loop as current for get_running_loop() to work
724
+ asyncio .set_event_loop (custom_loop )
725
+
726
+ # Create resolver with explicit loop parameter
727
+ resolver = AsyncResolver (loop = custom_loop )
728
+
729
+ # Check that the resolver uses the provided loop
730
+ assert resolver ._loop is custom_loop
731
+ finally :
732
+ asyncio .set_event_loop (None )
733
+ custom_loop .close ()
734
+
735
+
736
+ @pytest .mark .skipif (aiodns is None , reason = "aiodns required" )
737
+ @pytest .mark .usefixtures ("check_no_lingering_resolvers" )
738
+ async def test_async_resolver_uses_running_loop_when_none_provided () -> None :
739
+ """Test that AsyncResolver uses get_running_loop() when no loop is provided."""
740
+ # Create resolver without loop parameter
741
+ resolver = AsyncResolver ()
742
+
743
+ # Check that the resolver uses the current running loop
744
+ assert resolver ._loop is asyncio .get_running_loop ()
745
+
746
+ # Clean up
747
+ await resolver .close ()
You can’t perform that action at this time.
0 commit comments