diff --git a/sdk/core/azure-core/azure/core/pipeline/transport/_aiohttp.py b/sdk/core/azure-core/azure/core/pipeline/transport/_aiohttp.py index e32d0d1c0ae..e6189bd6e70 100644 --- a/sdk/core/azure-core/azure/core/pipeline/transport/_aiohttp.py +++ b/sdk/core/azure-core/azure/core/pipeline/transport/_aiohttp.py @@ -23,6 +23,7 @@ # IN THE SOFTWARE. # # -------------------------------------------------------------------------- +import sys from typing import Any, Optional, AsyncIterator as AsyncIteratorType from collections.abc import AsyncIterator try: @@ -58,7 +59,6 @@ class AioHttpTransport(AsyncHttpTransport): Fully asynchronous implementation using the aiohttp library. :param session: The client session. - :param loop: The event loop. :param bool session_owner: Session owner. Defaults True. :keyword bool use_env_settings: Uses proxy settings from environment. Defaults to True. @@ -73,6 +73,8 @@ class AioHttpTransport(AsyncHttpTransport): :caption: Asynchronous transport with aiohttp. """ def __init__(self, *, session: Optional[aiohttp.ClientSession] = None, loop=None, session_owner=True, **kwargs): + if loop and sys.version_info >= (3, 10): + raise ValueError("Starting with Python 3.10, asyncio doesn’t support loop as a parameter anymore") self._loop = loop self._session_owner = session_owner self.session = session diff --git a/sdk/core/azure-core/tests/test_basic_transport.py b/sdk/core/azure-core/tests/test_basic_transport.py index 5679b6629f4..d08feda5493 100644 --- a/sdk/core/azure-core/tests/test_basic_transport.py +++ b/sdk/core/azure-core/tests/test_basic_transport.py @@ -1138,3 +1138,11 @@ def test_conflict_timeout(caplog): with pytest.raises(ValueError): with Pipeline(transport) as pipeline: pipeline.run(request, connection_timeout=(100, 100), read_timeout = 100) + +@pytest.mark.skipif(sys.version_info < (3, 10), reason="Loop parameter is deprecated since Python 3.10") +def test_aiohttp_loop(): + import asyncio + from azure.core.pipeline.transport import AioHttpTransport + loop = asyncio._get_running_loop() + with pytest.raises(ValueError): + transport = AioHttpTransport(loop=loop)