terricain / aioboto3

Wrapper to use boto3 resources with the aiobotocore async backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type annotations

takeda opened this issue · comments

Are there plans to add type system?

While boto3 does not have type annotations, there is a package called boto3-stubs which provides type information making it more enjoyable to program in IDE.

Any plans for aioboto3, to include type annotations?

The author of boto3-stubs must be stalking me ;) This update was posted there 10 hours later:

https://github.com/vemel/mypy_boto3_builder/issues/4#issuecomment-1028776360

So, I am working on types-aiobotocore. They can be used for aioboto3 as well, smth like:

import aioboto3
from types_aiobotocore_s3.client import S3Client
from types_aiobotocore_s3.service_resource import S3ServiceResource

session = aioboto3.Session()

async with session.client("s3") as s3_client:
    s3_client: S3Client # now s3_client should have auto-complete and type checking
    
async with session.resource("s3") as s3_resource:
    s3_resource: S3ServiceResource # resource as well

Please let me know if you are interested. I can create stubs for aioboto3, but for now, it is out of my scope.

Yes, this sounds absolutely great. Thank you.

Once I get approval, I am going to publish all the packages. Everything works great already, I just need to add integration tests and setup automated builds (not sure if we really need them, as aiobotocore releases are quite rare)

I did not yet create documentation specifically for aioboto3 but I described how to use it in the comment above. Feel free to try: https://pypi.org/project/types-aiobotocore/

Hey, feel free :)

Let me know when you've got something in pypi and i'll add something to the readme

Hello! I already have types-aiobotocore on PyPI. I can provide a short example how to use it with aioboto3

types-aiobotocore is really awesome, definitely has saved me some bugs!

One usability issue - I am using with strict MyPy and unfortunately the import aioboto3 fails strict checking:

Skipping analyzing "aioboto3": module is installed,
but missing library stubs or py.typed marker  [import]
    import aioboto3
    ^
app/docs/s3.py:7: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

The auto-complete and type checking workaround from above do work well for autocompletion but they also require a type: ignore[no-redef] for strict mypy to pass:

async with self.boto_session.client("s3") as s3:
    s3: S3Client  # type: ignore[no-redef]

Ah ha! I fixed my ignore [no-redef] part! This has the added bonus that mypy type hints the result of the context manager:

async with self.boto_session.client("s3") as s3:  # type: S3Client
    s3.upload_fileobj(...)

I still have the issue with the aioboto3 import error but this works around the issue with redefinition and also being able to type hint the return of the context manager!

@vemel what do you think?