Skip to content

Commit

Permalink
Fix typing errors in older python builds
Browse files Browse the repository at this point in the history
  • Loading branch information
cahna committed Nov 10, 2024
1 parent 73897b7 commit 1ef637c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
21 changes: 13 additions & 8 deletions anymail/backends/mailtrap.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]],
},
)

Expand Down
9 changes: 7 additions & 2 deletions anymail/webhooks/mailtrap.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -74,6 +75,7 @@ brevo = []
mailersend = []
mailgun = []
mailjet = []
mailtrap = []
mandrill = []
postmark = []
resend = ["svix"]
Expand Down

0 comments on commit 1ef637c

Please sign in to comment.