22from urllib .parse import quote
33
44if sys .version_info < (3 , 11 ):
5- from typing_extensions import Any , Dict , List , Literal , NotRequired , TypedDict
5+ from typing import Any , Literal
6+
7+ from typing_extensions import NotRequired , TypedDict
68else :
7- from typing import Any , Dict , List , Literal , NotRequired , TypedDict
9+ from typing import Any , Literal , NotRequired , TypedDict
810
911from ..exceptions import AnymailRequestsAPIError
1012from ..message import AnymailMessage , AnymailRecipientStatus
@@ -31,29 +33,26 @@ class MailtrapAttachment(TypedDict):
3133 # Although "from" and "subject" are technically required,
3234 # allow Mailtrap's API to enforce that.
3335 "from" : NotRequired [MailtrapAddress ],
34- "to" : NotRequired [List [MailtrapAddress ]],
35- "cc" : NotRequired [List [MailtrapAddress ]],
36- "bcc" : NotRequired [List [MailtrapAddress ]],
36+ "to" : NotRequired [list [MailtrapAddress ]],
37+ "cc" : NotRequired [list [MailtrapAddress ]],
38+ "bcc" : NotRequired [list [MailtrapAddress ]],
3739 "reply_to" : NotRequired [MailtrapAddress ],
38- "attachments" : NotRequired [List [MailtrapAttachment ]],
39- "headers" : NotRequired [Dict [str , str ]],
40- "custom_variables" : NotRequired [Dict [str , str ]],
40+ "attachments" : NotRequired [list [MailtrapAttachment ]],
41+ "headers" : NotRequired [dict [str , str ]],
42+ "custom_variables" : NotRequired [dict [str , str ]],
4143 "subject" : NotRequired [str ],
4244 "text" : NotRequired [str ],
4345 "html" : NotRequired [str ],
4446 "category" : NotRequired [str ],
4547 "template_uuid" : NotRequired [str ],
46- "template_variables" : NotRequired [Dict [str , Any ]],
48+ "template_variables" : NotRequired [dict [str , Any ]],
4749 },
4850)
4951
50- MailtrapBatchData = TypedDict (
51- "MailtrapBatchData" ,
52- {
53- "base" : MailtrapData ,
54- "requests" : List [MailtrapData ],
55- },
56- )
52+
53+ class MailtrapBatchData (TypedDict ):
54+ base : MailtrapData
55+ requests : list [MailtrapData ]
5756
5857
5958class MailtrapPayload (RequestsPayload ):
@@ -74,14 +73,14 @@ def __init__(
7473 self .backend = backend
7574
7675 # Late bound batch send data
77- self .merge_data : Dict [str , Any ] = {}
78- self .merge_metadata : Dict [str , Dict [str , str ]] = {}
79- self .merge_headers : Dict [str , Dict [str , str ]] = {}
76+ self .merge_data = dict [str , Any ]()
77+ self .merge_metadata = dict [str , dict [str , str ]]()
78+ self .merge_headers = dict [str , dict [str , str ]]()
8079
8180 # needed for backend.parse_recipient_status
82- self .recipients_to : List [ str ] = []
83- self .recipients_cc : List [ str ] = []
84- self .recipients_bcc : List [ str ] = []
81+ self .recipients_to = list [ str ]()
82+ self .recipients_cc = list [ str ]()
83+ self .recipients_bcc = list [ str ]()
8584
8685 super ().__init__ (
8786 message , defaults , backend , * args , headers = http_headers , ** kwargs
@@ -141,7 +140,7 @@ def set_from_email(self, email: EmailAddress):
141140 self .data ["from" ] = email .as_dict (idna_encode = self .backend .idna_encode )
142141
143142 def set_recipients (
144- self , recipient_type : Literal ["to" , "cc" , "bcc" ], emails : List [EmailAddress ]
143+ self , recipient_type : Literal ["to" , "cc" , "bcc" ], emails : list [EmailAddress ]
145144 ):
146145 assert recipient_type in ["to" , "cc" , "bcc" ]
147146 if emails :
@@ -161,7 +160,7 @@ def set_subject(self, subject):
161160 # (must ignore default empty subject for use with template_uuid)
162161 self .data ["subject" ] = subject
163162
164- def set_reply_to (self , emails : List [EmailAddress ]):
163+ def set_reply_to (self , emails : list [EmailAddress ]):
165164 if len (emails ) == 1 :
166165 # Let Mailtrap handle the header generation (and EAI if needed)
167166 self .data ["reply_to" ] = emails [0 ].as_dict (
@@ -210,7 +209,7 @@ def add_attachment(self, attachment: Attachment):
210209 att ["content_id" ] = attachment .cid
211210 self .data .setdefault ("attachments" , []).append (att )
212211
213- def set_tags (self , tags : List [str ]):
212+ def set_tags (self , tags : list [str ]):
214213 if len (tags ) > 1 :
215214 self .unsupported_feature ("multiple tags" )
216215 if len (tags ) > 0 :
@@ -232,7 +231,7 @@ def set_merge_headers(self, merge_headers):
232231 # Late-bound in burst_for_batch
233232 self .merge_headers = merge_headers
234233
235- def set_merge_global_data (self , merge_global_data : Dict [str , Any ]):
234+ def set_merge_global_data (self , merge_global_data : dict [str , Any ]):
236235 self .data .setdefault ("template_variables" , {}).update (merge_global_data )
237236
238237 def set_merge_metadata (self , merge_metadata ):
@@ -315,7 +314,7 @@ def parse_recipient_status(
315314
316315 # Merge recipient statuses for each item in the batch.
317316 # Each API response includes message_ids in the order 'to', 'cc, 'bcc'.
318- recipient_status : Dict [str , AnymailRecipientStatus ] = {}
317+ recipient_status : dict [str , AnymailRecipientStatus ] = {}
319318 for to , one_response in zip (payload .recipients_to , responses ):
320319 recipients = [to , * payload .recipients_cc , * payload .recipients_bcc ]
321320 one_status = self .parse_one_response (
@@ -339,11 +338,11 @@ def parse_recipient_status(
339338 def parse_one_response (
340339 self ,
341340 one_response ,
342- recipients : List [str ],
341+ recipients : list [str ],
343342 raw_response ,
344343 payload : MailtrapPayload ,
345344 message : AnymailMessage ,
346- ) -> Dict [str , AnymailRecipientStatus ]:
345+ ) -> dict [str , AnymailRecipientStatus ]:
347346 """
348347 Return parsed status for recipients in one_response, which is either
349348 a top-level send response or an individual 'responses' item for batch send.
0 commit comments