youtype / botocore-stubs

Type annotations and code completion for botocore package
https://youtype.github.io/mypy_boto3_builder/
MIT License
3 stars 3 forks source link

URLLib3Session send has incorrect type hints #4

Closed SteggyLeggy closed 1 year ago

SteggyLeggy commented 1 year ago

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: ...
vemel commented 1 year ago

Thank you for the report!

Fixed and released botocore-stubs 1.31.12.post1. Please test once you have time and let me know if it works as it should.

SteggyLeggy commented 1 year ago

Amazing turn around, thank you @vemel yes that's fixed the issue.