youtype / botocore-stubs Goto Github PK
View Code? Open in Web Editor NEWType annotations and code completion for botocore package
License: MIT License
Type annotations and code completion for botocore package
License: MIT License
botocore-stubs/botocore-stubs/auth.pyi
Line 124 in 3dc924f
Type[BaseSigner]
, not BaseSigner
.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
.
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="",
)
invalid_signer
should either result in a mypy error, or should work when you call get_presigned_url
valid_signer
should either result in no mypy error, or should not work when you call get_presigned_url
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 errorgenerate_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.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!
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
.
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: ...
Boto dependency is failing since version 1.34.94. Other packages from boto3-stubs working fine
When updating to the newest version in the AUR the build fails and returns
Starting package()... /usr/sbin/python: can't open file '/home/user/.cache/yay/python-botocore-stubs/src/botocore_stubs-1.31.38/setup.py': [Errno 2] No such file or directory
It looks like setup.py
isn't in the source at https://files.pythonhosted.org/packages/1e/95/936de5991cd2f2eede891d1612ccce43d1bbeaf64329d1784357cd8574e6/botocore_stubs-1.31.38.tar.gz.
Why is _ClientErrorResponseTypeDef not include CancellationReasons
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.