Code Monkey home page Code Monkey logo

botocore-stubs's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

botocore-stubs's Issues

Incorrect type annotation for service_id parameter to botocore.signers.RequestSigner

Follow-up issue to youtype/mypy_boto3_builder#195 upon a bit of further testing, looks like I'm hitting an issue that's one part PyCharm issue, one part botocore-stubs issue.

In botocore's docstrings, it says that RequestSigner takes a botocore.model.ServiceId, however in botocore-stubs, it says it takes astr.

Repro

  • pip install boto3-stubs[sts]
import boto3
from botocore.signers import RequestSigner

session = boto3.session.Session(aws_access_key_id="test", aws_secret_access_key="test")
client = session.client("sts", region_name="ca-central-1")
service_id = client.meta.service_model.service_id

invalid_signer = RequestSigner(
    "sts",
    "ca-central-1",
    "sts",
    "v4",
    session.get_credentials(),
    session.events,
)

valid_signer = RequestSigner(
    service_id,
    "ca-central-1",
    "sts",
    "v4",
    session.get_credentials(),
    session.events,
)

invalid_signer.generate_presigned_url(
    {"method": "GET", "url": "", "body": {}, "headers": {}, "context": {}},
    region_name="ca-central-1",
    expires_in=60,
    operation_name="",
)

valid_signer.generate_presigned_url(
    {"method": "GET", "url": "", "body": {}, "headers": {}, "context": {}},
    region_name="ca-central-1",
    expires_in=60,
    operation_name="",
)

Expected result

  • The invalid_signer should either result in a mypy error, or should work when you call get_presigned_url
  • The valid_signer should either result in no mypy error, or should not work when you call get_presigned_url

Actual result

  • The call to generate_presigned_url on invalid_signer results in an attribute error due to attempting to access hyphenize on str, whereas it only exists on ServiceId, and does not result in a mypy error
  • The call to generate_presigned_url on valid_signer works, but gives a type error in PyCharm. This part is partially the PyCharm issue, as I'm pretty sure it's a false positive in PyCharm due to ServiceId that we're passing being a subclass of str, so even with the current type annotations I believe this should be valid.

image

SigV4Auth.signature() has incorrect return type

Hi!

The return type of botocore.auth.SigV4Auth.signature() should be str, not bytes:

https://github.com/youtype/botocore-stubs/blob/main/botocore-stubs/auth.pyi#L60

The return value is here: https://github.com/boto/botocore/blob/1bf422484a5abca0304d328b9ee2d91801acd2d6/botocore/auth.py#L414

which is calling the internal _sign function with hex=True:

https://github.com/boto/botocore/blob/1bf422484a5abca0304d328b9ee2d91801acd2d6/botocore/auth.py#L224

So it's getting hmac.new().hexdigest(), and that's str: https://github.com/python/typeshed/blob/main/stdlib/hmac.pyi#L42

Thanks for all your work!

Provide option to tie installable version of `botocore` to that of `botocore-stubs`

This request is inspired by the optional boto3 extra offered by boto3-stubs. Selecting the extra sets a hard pin on the versions of boto3 and botocore, effectively providing convenient synchronisation of those packages' installed versions:
pip install boto3==1.28.60 boto3-stubs[boto3] will install version 1.28.60 of both boto3 and boto3-stubs. Despite there being available a more recent version of boto3-stubs.

Such a simple mechanism might also be offered by botocore-stubs: A new extra named botocore would set a hard pin to the respective version of botocore.

URLLib3Session send has incorrect type hints

I believe the send function of has been updated to have some incorrect type hints.

def send(self, request: AWSRequest) -> None: ...

We've started getting a mypy error

error: Argument 1 to "send" of "URLLib3Session" has incompatible type "AWSPreparedRequest"; expected "AWSRequest"  [arg-type]

It's tricky to tell from the botocore source if the intention of the send function of URLLib3Session was intended to be a AWSPreparedRequest or AWSRequest (or perhaps maybe both?) But we have been passing in a prepared request for some time without any issue. And from what I can see of the source code, for that function, it doesn't use any part of the request that isn't in both AWSRequest and AWSPreparedRequest.

Also I'm a lot more sure of the return type being incorrect, as the send function clearly does this

    http_response = botocore.awsrequest.AWSResponse(
        request.url,
        urllib_response.status,
        urllib_response.headers,
        urllib_response,
    )
            
    # ... trimmed for brevity 
            
    return http_response

So I'm kind of inclined to believe the type hinting for send should be something like this...

def send(self, request: Union[AWSRequest, AWSPreparedRequest]) -> AWSResponse: ...

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.