Skip to content

Commit 1ef637c

Browse files
committed
Fix typing errors in older python builds
1 parent 73897b7 commit 1ef637c

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

anymail/backends/mailtrap.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import sys
12
import warnings
2-
from typing import Any, Literal, NotRequired, TypedDict
3+
4+
if sys.version_info < (3, 11):
5+
from typing_extensions import Any, Dict, List, Literal, NotRequired, TypedDict
6+
else:
7+
from typing import Any, Dict, List, Literal, NotRequired, TypedDict
38

49
from ..exceptions import AnymailRequestsAPIError, AnymailWarning
510
from ..message import AnymailMessage, AnymailRecipientStatus
@@ -24,18 +29,18 @@ class MailtrapAttachment(TypedDict):
2429
"MailtrapData",
2530
{
2631
"from": MailtrapAddress,
27-
"to": NotRequired[list[MailtrapAddress]],
28-
"cc": NotRequired[list[MailtrapAddress]],
29-
"bcc": NotRequired[list[MailtrapAddress]],
30-
"attachments": NotRequired[list[MailtrapAttachment]],
31-
"headers": NotRequired[dict[str, str]],
32-
"custom_variables": NotRequired[dict[str, str]],
32+
"to": NotRequired[List[MailtrapAddress]],
33+
"cc": NotRequired[List[MailtrapAddress]],
34+
"bcc": NotRequired[List[MailtrapAddress]],
35+
"attachments": NotRequired[List[MailtrapAttachment]],
36+
"headers": NotRequired[Dict[str, str]],
37+
"custom_variables": NotRequired[Dict[str, str]],
3338
"subject": str,
3439
"text": str,
3540
"html": NotRequired[str],
3641
"category": NotRequired[str],
3742
"template_id": NotRequired[str],
38-
"template_variables": NotRequired[dict[str, Any]],
43+
"template_variables": NotRequired[Dict[str, Any]],
3944
},
4045
)
4146

anymail/webhooks/mailtrap.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import json
2+
import sys
23
from datetime import datetime, timezone
3-
from typing import Literal, NotRequired, TypedDict
4+
5+
if sys.version_info < (3, 11):
6+
from typing_extensions import Dict, Literal, NotRequired, TypedDict, Union
7+
else:
8+
from typing import Dict, Literal, NotRequired, TypedDict, Union
49

510
from ..signals import AnymailTrackingEvent, EventType, RejectReason, tracking
611
from .base import AnymailBaseWebhookView
@@ -24,7 +29,7 @@ class MailtrapEvent(TypedDict):
2429
timestamp: int
2530
event_id: str
2631
category: NotRequired[str]
27-
custom_variables: NotRequired[dict[str, str | int | float | bool]]
32+
custom_variables: NotRequired[Dict[str, Union[str, int, float, bool]]]
2833
reason: NotRequired[str]
2934
response: NotRequired[str]
3035
response_code: NotRequired[int]

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ dependencies = [
6363
"django>=4.0",
6464
"requests>=2.4.3",
6565
"urllib3>=1.25.0", # requests dependency: fixes RFC 7578 header encoding
66+
"typing_extensions>=4.12", # for older Python compatibility
6667
]
6768

6869
[project.optional-dependencies]
@@ -74,6 +75,7 @@ brevo = []
7475
mailersend = []
7576
mailgun = []
7677
mailjet = []
78+
mailtrap = []
7779
mandrill = []
7880
postmark = []
7981
resend = ["svix"]

0 commit comments

Comments
 (0)