diff --git a/anymail/backends/mailtrap.py b/anymail/backends/mailtrap.py index 35cc6499..4517f708 100644 --- a/anymail/backends/mailtrap.py +++ b/anymail/backends/mailtrap.py @@ -1,5 +1,10 @@ +import sys import warnings -from typing import Any, Literal, NotRequired, TypedDict + +if sys.version_info < (3, 11): + from typing_extensions import Any, Dict, List, Literal, NotRequired, TypedDict +else: + from typing import Any, Dict, List, Literal, NotRequired, TypedDict from ..exceptions import AnymailRequestsAPIError, AnymailWarning from ..message import AnymailMessage, AnymailRecipientStatus @@ -24,18 +29,18 @@ class MailtrapAttachment(TypedDict): "MailtrapData", { "from": MailtrapAddress, - "to": NotRequired[list[MailtrapAddress]], - "cc": NotRequired[list[MailtrapAddress]], - "bcc": NotRequired[list[MailtrapAddress]], - "attachments": NotRequired[list[MailtrapAttachment]], - "headers": NotRequired[dict[str, str]], - "custom_variables": NotRequired[dict[str, str]], + "to": NotRequired[List[MailtrapAddress]], + "cc": NotRequired[List[MailtrapAddress]], + "bcc": NotRequired[List[MailtrapAddress]], + "attachments": NotRequired[List[MailtrapAttachment]], + "headers": NotRequired[Dict[str, str]], + "custom_variables": NotRequired[Dict[str, str]], "subject": str, "text": str, "html": NotRequired[str], "category": NotRequired[str], "template_id": NotRequired[str], - "template_variables": NotRequired[dict[str, Any]], + "template_variables": NotRequired[Dict[str, Any]], }, ) diff --git a/anymail/webhooks/mailtrap.py b/anymail/webhooks/mailtrap.py index 2e97ef95..d554cbe4 100644 --- a/anymail/webhooks/mailtrap.py +++ b/anymail/webhooks/mailtrap.py @@ -1,6 +1,11 @@ import json +import sys from datetime import datetime, timezone -from typing import Literal, NotRequired, TypedDict + +if sys.version_info < (3, 11): + from typing_extensions import Dict, Literal, NotRequired, TypedDict, Union +else: + from typing import Dict, Literal, NotRequired, TypedDict, Union from ..signals import AnymailTrackingEvent, EventType, RejectReason, tracking from .base import AnymailBaseWebhookView @@ -24,7 +29,7 @@ class MailtrapEvent(TypedDict): timestamp: int event_id: str category: NotRequired[str] - custom_variables: NotRequired[dict[str, str | int | float | bool]] + custom_variables: NotRequired[Dict[str, Union[str, int, float, bool]]] reason: NotRequired[str] response: NotRequired[str] response_code: NotRequired[int] diff --git a/pyproject.toml b/pyproject.toml index b4f67861..76523c5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,6 +63,7 @@ dependencies = [ "django>=4.0", "requests>=2.4.3", "urllib3>=1.25.0", # requests dependency: fixes RFC 7578 header encoding + "typing_extensions>=4.12", # for older Python compatibility ] [project.optional-dependencies] @@ -74,6 +75,7 @@ brevo = [] mailersend = [] mailgun = [] mailjet = [] +mailtrap = [] mandrill = [] postmark = [] resend = ["svix"]