Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type annotations #255

Open
takeda opened this issue Feb 2, 2022 · 11 comments
Open

Type annotations #255

takeda opened this issue Feb 2, 2022 · 11 comments

Comments

@takeda
Copy link

takeda commented Feb 2, 2022

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?

@takeda
Copy link
Author

takeda commented Feb 3, 2022

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

@vemel
Copy link

vemel commented Feb 5, 2022

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.

@takeda
Copy link
Author

takeda commented Feb 5, 2022

Yes, this sounds absolutely great. Thank you.

@vemel
Copy link

vemel commented Feb 5, 2022

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)

@vemel
Copy link

vemel commented Feb 7, 2022

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/

@terricain
Copy link
Owner

Hey, feel free :)

@terricain
Copy link
Owner

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

@vemel
Copy link

vemel commented Mar 14, 2022

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

@phillipuniverse
Copy link

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]

@phillipuniverse
Copy link

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?

@zsinx6
Copy link

zsinx6 commented Oct 6, 2022

@phillipuniverse This one fix the issue: youtype/mypy_boto3_builder#153 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants