Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 10, 2024 19:36
Show Gist options
  • Save mypy-play/58bb0ba52acb5da1842c6496905c9aae to your computer and use it in GitHub Desktop.
Save mypy-play/58bb0ba52acb5da1842c6496905c9aae to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import ParamSpec, TypeVar, Callable, Literal, NewType
from dataclasses import dataclass
S3EventType = Literal["S3"]
SQSEventType = Literal["SQS"]
SQSRecord = NewType("SQSRecord", str)
AWSEventTypes = S3EventType | SQSEventType
@dataclass(frozen=True)
class S3EventData:
type: S3EventType
object_key: str
@dataclass(frozen=True)
class SQSEventData:
type: SQSEventType
records: list[SQSRecord]
P = ParamSpec('P')
R = TypeVar('R')
EventHandler = Callable[P, R]
RegisteredEventHandlers = dict[AWSEventTypes, EventHandler[P, R]]
_registered_event_handlers: RegisteredEventHandlers[P, R] = {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment