From ad0b5819898e15be5fa0abc4e0505048ec35f1a2 Mon Sep 17 00:00:00 2001 From: Jakob Keller <57402305+jakob-keller@users.noreply.github.com> Date: Sun, 18 Aug 2024 18:07:42 +0200 Subject: [PATCH] remove legacy `asynccontextmanager` import from `_helpers` --- aiobotocore/_helpers.py | 9 --------- aiobotocore/utils.py | 4 ++-- tests/boto_tests/helpers.py | 3 +-- tests/boto_tests/test_credentials.py | 2 +- tests/boto_tests/test_utils.py | 2 +- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/aiobotocore/_helpers.py b/aiobotocore/_helpers.py index fceb11e0..e6f7e835 100644 --- a/aiobotocore/_helpers.py +++ b/aiobotocore/_helpers.py @@ -1,14 +1,5 @@ import inspect -try: - from contextlib import ( # noqa: F401 lgtm[py/unused-import] - asynccontextmanager, - ) -except ImportError: - from async_generator import ( # noqa: F401 E501, lgtm[py/unused-import] - asynccontextmanager, - ) - async def resolve_awaitable(obj): if inspect.isawaitable(obj): diff --git a/aiobotocore/utils.py b/aiobotocore/utils.py index f7df88f1..b97318af 100644 --- a/aiobotocore/utils.py +++ b/aiobotocore/utils.py @@ -1,4 +1,5 @@ import asyncio +import contextlib import functools import inspect import json @@ -34,7 +35,6 @@ ) import aiobotocore.httpsession -from aiobotocore._helpers import asynccontextmanager logger = logging.getLogger(__name__) @@ -45,7 +45,7 @@ def __init__(self, *args, **kwargs): self.__ref_count = 0 self.__lock = None - @asynccontextmanager + @contextlib.asynccontextmanager async def acquire(self): if not self.__lock: self.__lock = asyncio.Lock() diff --git a/tests/boto_tests/helpers.py b/tests/boto_tests/helpers.py index bb4e74fc..563cfe1d 100644 --- a/tests/boto_tests/helpers.py +++ b/tests/boto_tests/helpers.py @@ -1,9 +1,8 @@ -from contextlib import AsyncExitStack +from contextlib import AsyncExitStack, asynccontextmanager from botocore.stub import Stubber import aiobotocore.session -from aiobotocore._helpers import asynccontextmanager class StubbedSession(aiobotocore.session.AioSession): diff --git a/tests/boto_tests/test_credentials.py b/tests/boto_tests/test_credentials.py index 5711c63d..73df755a 100644 --- a/tests/boto_tests/test_credentials.py +++ b/tests/boto_tests/test_credentials.py @@ -8,6 +8,7 @@ import sys import tempfile import uuid +from contextlib import asynccontextmanager from datetime import datetime, timedelta from functools import partial from typing import Optional @@ -31,7 +32,6 @@ from dateutil.tz import tzlocal, tzutc from aiobotocore import credentials -from aiobotocore._helpers import asynccontextmanager from aiobotocore.credentials import ( AioAssumeRoleProvider, AioCanonicalNameCredentialSourcer, diff --git a/tests/boto_tests/test_utils.py b/tests/boto_tests/test_utils.py index 40dd2fff..8a3cb7bd 100644 --- a/tests/boto_tests/test_utils.py +++ b/tests/boto_tests/test_utils.py @@ -2,6 +2,7 @@ import itertools import json +from contextlib import asynccontextmanager from typing import Iterator, Tuple, Union import pytest @@ -9,7 +10,6 @@ from botocore.utils import BadIMDSRequestError from aiobotocore import utils -from aiobotocore._helpers import asynccontextmanager # TypeAlias (requires typing_extensions or >=3.10 to annotate) Response = Tuple[Union[str, object], int]