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

isinstance(s3_client, S3Client) is false, should I expect True? #203

Closed chen2073 closed 1 year ago

chen2073 commented 1 year ago

Describe the bug I have boto3 type stubs installed and initialized a S3 client, I tried assigning this s3 client to pydantic BaseSettings and it failed validation where s3_client is not a S3Client

To Reproduce Steps to reproduce the behavior:

  1. Install boto3-stubs[all]
from boto3.session import Session
from mypy_boto3_s3.client import S3Client
s3_client = Session().client("s3")
isinstance(s3_client, S3Client)
...
**Actual output**

False
...
**Expected output**

True
...
vemel commented 1 year ago

Hello!

In your example s3_client has type boto3.client.BaseClient in runtime. S3Client can be used only during type checking.

You can check client service name in runtime using

from boto3.session import Session
from mypy_boto3_s3.client import S3Client

s3_client = Session().client("s3")
s3_client.meta.service_model.service_name == "s3"

Please let me know if this helps.

chen2073 commented 1 year ago

Thank you for the response, I will give it a try