Skip to content

Commit

Permalink
Wrap aiobotocore create_client return types in ClientCreatorContext
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Nov 26, 2024
1 parent f139054 commit 09f2492
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
7 changes: 6 additions & 1 deletion mypy_boto3_builder/parsers/parse_wrapper_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ def parse_aiobotocore_stubs_package(
"""
package = TypesAioBotocorePackage(package_data, service_names, version)
parser = WrapperPackageParser(package)
package.session_class.methods.extend(parser.get_session_client_methods("create_client"))
for method in parser.get_session_client_methods("create_client"):
method.return_type = TypeSubscript(
InternalImport("ClientCreatorContext", stringify=False),
[method.return_type],
)
package.session_class.methods.append(method)
return package


Expand Down
10 changes: 6 additions & 4 deletions mypy_boto3_builder/stubs_static/types-aiobotocore/session.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from types import TracebackType
from typing import Any, List, Optional, Type, Union
from typing import Any, Generic, List, Optional, Type, TypeVar, Union

from aiobotocore.client import AioBaseClient as AioBaseClient
from aiobotocore.client import AioClientCreator as AioClientCreator
Expand All @@ -12,9 +12,11 @@ from botocore.model import ServiceModel
from botocore.session import EVENT_ALIASES as EVENT_ALIASES
from botocore.session import Session

class ClientCreatorContext:
_AioBaseClient = TypeVar("_AioBaseClient", bound="AioBaseClient")

class ClientCreatorContext(Generic[_AioBaseClient]):
def __init__(self, coro: Any) -> None: ...
async def __aenter__(self) -> AioBaseClient: ...
async def __aenter__(self) -> _AioBaseClient: ...
async def __aexit__(
self,
exc_type: Optional[Type[BaseException]],
Expand Down Expand Up @@ -49,7 +51,7 @@ class AioSession(Session):
aws_secret_access_key: Optional[str] = ...,
aws_session_token: Optional[str] = ...,
config: Optional[Config] = ...,
) -> AioBaseClient: ...
) -> ClientCreatorContext[AioBaseClient]: ...
async def get_credentials(self) -> Optional[AioCredentials]: ... # type: ignore [override]
def set_credentials(
self, access_key: str, secret_key: str, token: Optional[Any] = ...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from types import TracebackType
from typing import Any, List, Type, Optional
from typing import Any, Generic, List, Optional, Type, TypeVar, Union

from aiobotocore.client import AioBaseClient as AioBaseClient
from aiobotocore.client import AioClientCreator as AioClientCreator
Expand All @@ -16,9 +16,11 @@ from botocore.session import Session as BotocoreSession
{{ import_record -}}{{ "\n" -}}
{% endfor -%}

class ClientCreatorContext:
_AioBaseClient = TypeVar("_AioBaseClient", bound="AioBaseClient")

class ClientCreatorContext(Generic[_AioBaseClient]):
def __init__(self, coro: Any) -> None: ...
async def __aenter__(self) -> AioBaseClient: ...
async def __aenter__(self) -> _AioBaseClient: ...
async def __aexit__(
self,
exc_type: Optional[Type[BaseException]],
Expand Down

0 comments on commit 09f2492

Please sign in to comment.