Skip to content

Commit 8c44826

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

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

anymail/backends/mailtrap.py

Lines changed: 6 additions & 1 deletion
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, Literal, NotRequired, TypedDict
6+
else:
7+
from typing import Any, Literal, NotRequired, TypedDict
38

49
from ..exceptions import AnymailRequestsAPIError, AnymailWarning
510
from ..message import AnymailMessage, AnymailRecipientStatus

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 Literal, NotRequired, TypedDict, Union
7+
else:
8+
from typing import 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)