-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Wrong type for aioboto3
resource context manager
#325
Comments
Thank you for the report! I will test the proposed change and include it to the next release. |
Accidentally closed. Reopened. |
Fixed in # clone git repo
git clone [email protected]:youtype/mypy_boto3_builder.git
cd mypy_boto3_builder
# this will create mypy_boto3_output/types_aioboto3_stubs_package with ready to install package
# you might need uv: https://docs.astral.sh/uv/getting-started/installation/
uv run python -m mypy_boto3_builder mypy_boto3_output --product aioboto3 --no-smart-version
# install types-aioboto3 to active Python env
python mypy_boto3_output/types_aioboto3_package/setup.py install Then, you can run type checker on your project. Thank you! |
Thank you @vemel for quickly working on this! It works like a charm for But one more thing, I think you need to do the same for s3_client_context: ClientCreatorContext[S3Client] = aioboto3.Session().client("s3") Thus, async with aioboto3.Session().client("s3") as s3_client:
assert isinstance(s3_client, S3Client) |
Makes sense. This is not directly related to |
@vemel Thanks for the release, but I don't think a new types-aioboto3 has been released yet. When will a new version be released to PyPI? |
Hello! I just released
with the fix included. Could you please test if it works as expected and let me know? |
Just checked with the following newly published package. Works. Thank you!
|
Good call! Fixed release script, published |
Looks great. I am assuming that this |
Describe the bug
Currently the
aioboto3
type generator creates the following incorrect type hint (snippet fromaioboto3-stubs/session.pyi
).To Reproduce
The proper
aioboto3
usage is the following wheredynamodb: DynamoDBServiceResource
The current type hint generator makes it seem like following is also possible because type checker will think that
dynamodb: DynamoDBServiceResource
. But it is NOT possible since the.resource()
returnsResourceCreatorContext
type that needs to go throughawait __aenter__()
before it becomesDynamoDBServiceResource
type. Thus, this will cause a run-time error.Solution
The correct type hint would be something along the lines of the following.
DynamoDBServiceResource
itself should not be an async context manager.Additional context
The text was updated successfully, but these errors were encountered: