youtype / mypy_boto3_builder

Type annotations builder for boto3 compatible with VSCode, PyCharm, Emacs, Sublime Text, pyright and mypy.
https://youtype.github.io/mypy_boto3_builder/
MIT License
544 stars 36 forks source link

Sub-resources do not inherit correct `.meta.client` type #239

Closed alexmv closed 9 months ago

alexmv commented 9 months ago

Describe the bug

While s3_resource.meta.client is a S3Client, s3_resource.bucket("...").meta.client is only a bare BaseClient.

To Reproduce Steps to reproduce the behavior:

  1. Install boto3-stubs[...]
  2. Run mypy/pyright on the following code sample
import boto3

s3_resource = boto3.resource("s3")
bucket = s3_resource.Bucket("example")

reveal_type(s3_resource.meta.client)
reveal_type(bucket.meta.client)

Actual output

test.py:6: note: Revealed type is "mypy_boto3_s3.client.S3Client"
test.py:7: note: Revealed type is "botocore.client.BaseClient"

Expected output

test.py:6: note: Revealed type is "mypy_boto3_s3.client.S3Client"
test.py:7: note: Revealed type is "mypy_boto3_s3.client.S3Client"

Additional context On Linux, boto3-stubs version 1.34.13, boto3 version 1.33.10.

See #101 for related previous issue.

vemel commented 9 months ago

Hello. Thanks for the report. Yes, it makes sense to use service-specific meta for all resources. I will try to release an update soon.

vemel commented 9 months ago

I just released mypy-boto3-s3 1.34.14 with the fixes included. I did not update other service packages, so let me know if you depend on any.

Please update and let me know if it works as expected.

alexmv commented 9 months ago

It works great -- thanks for the quick fix!