Incorrect return type for boto3.session.Session.events
nint8835 opened this issue · 3 comments
Describe the bug
Currently, this package defines the return type of boto3.session.Session.events
as List[Any]
. This causes issues if you go to pass this as the event_handler
arg to a botocore function, as they expect to get a BaseEventHooks
.
As far as I can tell, BaseEventHooks
is what the return type should be, as it's returning the event_handler
component which is instantiated as either BaseEventHooks
or a subclass of it within botocore
To Reproduce
Steps to reproduce the behavior:
- Install
boto3-stubs[sts]
- Run
mypy
/pyright
on the following code sample
import boto3
from botocore.signers import RequestSigner
session = boto3.session.Session()
client = session.client("sts", region_name="ca-central-1")
service_id = client.meta.service_model.service_id
signer = RequestSigner(
service_id,
"ca-central-1",
"sts",
"v4",
session.get_credentials(),
session.events,
)
(based on this sample from AWS)
Actual output
error: Argument 6 to "RequestSigner" has incompatible type "List[Any]"; expected "BaseEventHooks" [arg-type]
Expected output
No issues found
Additional context
Occurs on the latest versions of boto3 (1.26.102), botocore (1.29.102), boto3-stubs (1.26.102), and botocore-stubs (1.29.102) as of time of writing.
Thanks for the report.
Looks like type annotations for RequestSigner
are correct:
:type event_emitter: :py:class:`~botocore.hooks.BaseEventHooks`
:param event_emitter: Extension mechanism to fire events.
So it must be Session.events
type annotation. I will try to fix it ASAP.
@nint8835 Fixed in boto3-stubs 1.26.103.post1
. Please update and let me know if it works for you as expected.
From a quick test looks good to me - thanks for the quick fix!