mypy: Use Python 3 type syntax in zerver/lib/send_email.py.

This commit is contained in:
nyan-salmon
2017-12-24 15:03:33 +00:00
committed by showell
parent 4f4d689f86
commit 613856c33b

View File

@@ -25,9 +25,10 @@ class FromAddress:
SUPPORT = parseaddr(settings.ZULIP_ADMINISTRATOR)[1]
NOREPLY = parseaddr(settings.NOREPLY_EMAIL_ADDRESS)[1]
def build_email(template_prefix, to_user_id=None, to_email=None, from_name=None,
from_address=None, reply_to_email=None, context=None):
# type: (str, Optional[int], Optional[Text], Optional[Text], Optional[Text], Optional[Text], Optional[Dict[str, Any]]) -> EmailMultiAlternatives
def build_email(template_prefix: str, to_user_id: Optional[int]=None,
to_email: Optional[Text]=None, from_name: Optional[Text]=None,
from_address: Optional[Text]=None, reply_to_email: Optional[Text]=None,
context: Optional[Dict[str, Any]]=None) -> EmailMultiAlternatives:
# Callers should pass exactly one of to_user_id and to_email.
assert (to_user_id is None) ^ (to_email is None)
if to_user_id is not None:
@@ -83,9 +84,9 @@ class EmailNotDeliveredException(Exception):
# When changing the arguments to this function, you may need to write a
# migration to change or remove any emails in ScheduledEmail.
def send_email(template_prefix, to_user_id=None, to_email=None, from_name=None,
from_address=None, reply_to_email=None, context={}):
# type: (str, Optional[int], Optional[Text], Optional[Text], Optional[Text], Optional[Text], Dict[str, Any]) -> None
def send_email(template_prefix: str, to_user_id: Optional[int]=None, to_email: Optional[Text]=None,
from_name: Optional[Text]=None, from_address: Optional[Text]=None,
reply_to_email: Optional[Text]=None, context: Dict[str, Any]={}) -> None:
mail = build_email(template_prefix, to_user_id=to_user_id, to_email=to_email, from_name=from_name,
from_address=from_address, reply_to_email=reply_to_email, context=context)
template = template_prefix.split("/")[-1]
@@ -98,9 +99,10 @@ def send_email(template_prefix, to_user_id=None, to_email=None, from_name=None,
def send_email_from_dict(email_dict: Mapping[str, Any]) -> None:
send_email(**dict(email_dict))
def send_future_email(template_prefix, realm, to_user_id=None, to_email=None, from_name=None,
from_address=None, context={}, delay=datetime.timedelta(0)):
# type: (str, Realm, Optional[int], Optional[Text], Optional[Text], Optional[Text], Dict[str, Any], datetime.timedelta) -> None
def send_future_email(template_prefix: str, realm: Realm, to_user_id: Optional[int]=None,
to_email: Optional[Text]=None, from_name: Optional[Text]=None,
from_address: Optional[Text]=None, context: Dict[str, Any]={},
delay: datetime.timedelta=datetime.timedelta(0)) -> None:
template_name = template_prefix.split('/')[-1]
email_fields = {'template_prefix': template_prefix, 'to_user_id': to_user_id, 'to_email': to_email,
'from_name': from_name, 'from_address': from_address, 'context': context}