Git Product home page Git Product logo

Comments (10)

vemel avatar vemel commented on May 23, 2024 1

@tuukkamustonen there is a new branch that addresses this issue: https://github.com/vemel/mypy_boto3_builder/pull/47

Should be released in a couple of days.

from mypy_boto3_builder.

takeda avatar takeda commented on May 23, 2024

I think this bug happens to all clients. I get it with EC2, Organizations, SSM, StepFunctions.

Based on my understanding how types work I think PyCharm is right (assuming SSMClient is child of BaseClient), but mypy doesn't show this error.

from mypy_boto3_builder.

takeda avatar takeda commented on May 23, 2024

@vlasovskikh since you're working on PyCharm, can you tell if there's something wrong with these stubs?

from mypy_boto3_builder.

tuukkamustonen avatar tuukkamustonen commented on May 23, 2024

Having the same issue with PyCharm 2020.2 (didn't try earlier) and:

boto3                         1.14.47
boto3-stubs                   1.14.47.0
mypy-boto3                    1.14.47.0
mypy-boto3-s3                 1.14.47.0
import boto3
from mypy_boto3_s3 import S3Client
client: S3Client = boto3.client('s3')

Navigating to boto3.client() goes to site-packages/mypy_boto3/boto3_init_gen.py which shows:

# pylint: disable=unused-argument
def client(
    service_name: str,
    region_name: str = None,
    api_version: str = None,
    use_ssl: bool = None,
    verify: Union[str, bool] = None,
    endpoint_url: str = None,
    aws_access_key_id: str = None,
    aws_secret_access_key: str = None,
    aws_session_token: str = None,
    config: Config = None,
) -> BaseClient:
    pass

So it indeed returns BaseClient and not S3Client.

Actually, interesting that boto3-stubs hijacks the navigation like that. How can I navigate (Ctrl+click) to the actual boto3 function then?

from mypy_boto3_builder.

vemel avatar vemel commented on May 23, 2024

Hello guys,

Thank you for the report. I have not found any cleaner way to annotate client classes.

As a workaround, you can run mypy_boto3, it will generate overloads in site-packages/mypy_boto3/boto3_init_gen.py.

If you have any suggestion - please let me know.

from mypy_boto3_builder.

vemel avatar vemel commented on May 23, 2024

The latest release should fix this issue. Thank you for the report. Let me know if still does not work correctly.

from mypy_boto3_builder.

takeda avatar takeda commented on May 23, 2024

@vemel I still see the issue on 1.14.51.1 for ec2: EC2Client = boto3.client("ec2", region_name=region)

Wouldn't setting boto3.client's result to Any fix it?

from mypy_boto3_builder.

takeda avatar takeda commented on May 23, 2024

Interestingly ec2: EC2ServiceResource = boto3.resource("ec2", region_name=region) is not highlighted. So, is there anything that's different between client() and resource()?

from mypy_boto3_builder.

vemel avatar vemel commented on May 23, 2024

THere is a difference, but I was sure I fixed both cases. Could you please try mypy on this code sample? https://github.com/vemel/mypy_boto3_builder/blob/master/examples/s3_example.py

The difference could be that client returns botocore.BaseClient, but resource() -> Any.

from mypy_boto3_builder.

tuukkamustonen avatar tuukkamustonen commented on May 23, 2024

@vemel Unfortunately, 1.14.53.0 still returns BaseClient for .client()... .resource() is indeed Any.

I did pip uninstall + pip install (instead of pip install -U) to ensure there wouldn't be leftovers from previous version.

from mypy_boto3_builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.