First attempts to use type hinting

This commit is contained in:
Patrick Jentsch
2021-12-07 14:18:05 +01:00
parent 9d30dda733
commit e1004a0181
6 changed files with 77 additions and 69 deletions

View File

@ -1,17 +1,25 @@
from flask import current_app, render_template
from flask_mail import Message
from typing import Any, Text
from . import mail
from .decorators import background
def create_message(recipient, subject, template, **kwargs):
msg = Message('{} {}'.format(current_app.config['NOPAQUE_MAIL_SUBJECT_PREFIX'], subject), recipients=[recipient]) # noqa
msg.body = render_template('{}.txt.j2'.format(template), **kwargs)
msg.html = render_template('{}.html.j2'.format(template), **kwargs)
def create_message(
recipient: str,
subject: str,
template: str,
**kwargs: Any
) -> Message:
subject_prefix: str = current_app.config['NOPAQUE_MAIL_SUBJECT_PREFIX']
msg: Message = Message(
f'{subject_prefix} {subject}', recipients=[recipient])
msg.body: Text = render_template(f'{template}.txt.j2', **kwargs)
msg.html: Text = render_template(f'{template}.html.j2', **kwargs)
return msg
@background
def send(msg, *args, **kwargs):
def send(msg: Message, *args, **kwargs):
with kwargs['app'].app_context():
mail.send(msg)