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

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

Closed nint8835 closed 1 year ago

nint8835 commented 1 year ago

Follow-up issue to https://github.com/youtype/mypy_boto3_builder/issues/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

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

Actual result

vemel commented 1 year ago

Thank you for this well-written bug report!

I fixed service_id: ServiceId argument type. The fix is included in botocore-stubs 1.29.103.post1. Please test it and let me know if it works as expected. Regarding PyCharm issue - I will check if it works as well.

nint8835 commented 1 year ago

Tested and confirmed the mypy issue is resolved, thanks once again for the quick fix!

With regards to the PyCharm issue, I'm still running into it but a bit differently now - I'm getting

Expected type 'ServiceId | ServiceId', got '() -> ServiceId | CachedProperty' instead

When trying to pass session.client(...).meta.service_model.service_id as the service_id argument. My best guess is it's probably something on the go with the CachedProperty decorator on the service_id in the service_model. I know PyCharm doesn't properly support some recent mypy features, that might be what's on the go there. I can open a separate issue for that problem if you want, I'm also content to just leave it as it is where it seems to be an editor-specific issue.