Skip to content

Commit

Permalink
Allow lazy translation strings in email contexts (#1442)
Browse files Browse the repository at this point in the history
  • Loading branch information
realsuayip authored Apr 17, 2023
1 parent 9e52a6c commit 67ec985
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
5 changes: 4 additions & 1 deletion django-stubs/contrib/auth/models.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from django.db import models
from django.db.models import QuerySet
from django.db.models.base import Model
from django.db.models.manager import EmptyManager
from django.utils.functional import _StrOrPromise
from typing_extensions import Literal, TypeAlias

_AnyUser: TypeAlias = Model | AnonymousUser
Expand Down Expand Up @@ -81,7 +82,9 @@ class AbstractUser(AbstractBaseUser, PermissionsMixin):
USERNAME_FIELD: str
def get_full_name(self) -> str: ...
def get_short_name(self) -> str: ...
def email_user(self, subject: str, message: str, from_email: str = ..., **kwargs: Any) -> None: ...
def email_user(
self, subject: _StrOrPromise, message: _StrOrPromise, from_email: str = ..., **kwargs: Any
) -> None: ...

class User(AbstractUser): ...

Expand Down
10 changes: 5 additions & 5 deletions django-stubs/core/mail/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from .utils import CachedDnsName as CachedDnsName
def get_connection(backend: str | None = ..., fail_silently: bool = ..., **kwds: Any) -> Any: ...
def send_mail(
subject: _StrOrPromise,
message: str,
message: _StrOrPromise,
from_email: str | None,
recipient_list: Sequence[str],
fail_silently: bool = ...,
Expand All @@ -33,15 +33,15 @@ def send_mass_mail(
connection: Any | None = ...,
) -> int: ...
def mail_admins(
subject: str,
message: str,
subject: _StrOrPromise,
message: _StrOrPromise,
fail_silently: bool = ...,
connection: Any | None = ...,
html_message: str | None = ...,
) -> None: ...
def mail_managers(
subject: str,
message: str,
subject: _StrOrPromise,
message: _StrOrPromise,
fail_silently: bool = ...,
connection: Any | None = ...,
html_message: str | None = ...,
Expand Down
13 changes: 7 additions & 6 deletions django-stubs/core/mail/message.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from email.mime.text import MIMEText
# remove Optional once python 3.7 is dropped (Tuple[str | None, ...] works with mypy on py3.10)
from typing import Any, Optional, Tuple, overload # noqa: Y022, Y037

from django.utils.functional import _StrOrPromise
from typing_extensions import TypeAlias

utf8_charset: Any
Expand Down Expand Up @@ -82,15 +83,15 @@ class EmailMessage:
bcc: list[Any]
reply_to: list[Any]
from_email: str
subject: str
body: str
subject: _StrOrPromise
body: _StrOrPromise
attachments: list[Any]
extra_headers: dict[Any, Any]
connection: Any
def __init__(
self,
subject: str = ...,
body: str | None = ...,
subject: _StrOrPromise = ...,
body: _StrOrPromise | None = ...,
from_email: str | None = ...,
to: Sequence[str] | None = ...,
bcc: Sequence[str] | None = ...,
Expand Down Expand Up @@ -118,8 +119,8 @@ class EmailMultiAlternatives(EmailMessage):
alternatives: list[tuple[_AttachmentContent, str]]
def __init__(
self,
subject: str = ...,
body: str | None = ...,
subject: _StrOrPromise = ...,
body: _StrOrPromise | None = ...,
from_email: str | None = ...,
to: Sequence[str] | None = ...,
bcc: Sequence[str] | None = ...,
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/utils/log.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from typing import Any

from django.core.management.color import Style
from django.http import HttpRequest, HttpResponse
from django.utils.functional import _StrOrPromise

request_logger: Logger
DEFAULT_LOGGING: Any
Expand All @@ -20,7 +21,7 @@ class AdminEmailHandler(logging.Handler):
email_backend: str | None = ...,
reporter_class: str | None = ...,
) -> None: ...
def send_mail(self, subject: str, message: str, *args: Any, **kwargs: Any) -> None: ...
def send_mail(self, subject: _StrOrPromise, message: _StrOrPromise, *args: Any, **kwargs: Any) -> None: ...
def connection(self) -> Any: ...
def format_subject(self, subject: str) -> str: ...

Expand Down

0 comments on commit 67ec985

Please sign in to comment.