From 3cfe137436fdf18c42f487e9cf52c3c66c92c06d Mon Sep 17 00:00:00 2001 From: PIG208 <359101898@qq.com> Date: Wed, 11 Aug 2021 23:24:38 +0800 Subject: [PATCH] Return Promise for lazy functions. Django uses a proxy method for lazy translation functions that actually returns instances of `Promise` instead of `str`. Fixes #688. --- django-stubs/utils/translation/__init__.pyi | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/django-stubs/utils/translation/__init__.pyi b/django-stubs/utils/translation/__init__.pyi index a867ca6869..62b2954107 100644 --- a/django-stubs/utils/translation/__init__.pyi +++ b/django-stubs/utils/translation/__init__.pyi @@ -4,6 +4,7 @@ from contextlib import ContextDecorator from typing import Any, Callable, Optional, Type, Union from django.http.request import HttpRequest +from django.utils.functional import Promise LANGUAGE_SESSION_KEY: str @@ -33,14 +34,14 @@ def ngettext(singular: str, plural: str, number: float) -> str: ... def ungettext(singular: str, plural: str, number: float) -> str: ... def pgettext(context: str, message: str) -> str: ... def npgettext(context: str, singular: str, plural: str, number: int) -> str: ... +def gettext_lazy(message: str) -> Promise: ... +def pgettext_lazy(context: str, message: str) -> Promise: ... +def ngettext_lazy(singular: str, plural: str, number: Union[int, str, None]) -> Promise: ... -gettext_lazy = gettext -pgettext_lazy = pgettext +ugettext_lazy = gettext_lazy +ungettext_lazy = ngettext_lazy -def ugettext_lazy(message: str) -> str: ... -def ngettext_lazy(singular: str, plural: str, number: Union[int, str, None] = ...) -> str: ... -def ungettext_lazy(singular: str, plural: str, number: Union[int, str, None] = ...) -> str: ... -def npgettext_lazy(context: str, singular: str, plural: str, number: Union[int, str, None] = ...) -> str: ... +def npgettext_lazy(context: str, singular: str, plural: str, number: Union[int, str, None]) -> Promise: ... def activate(language: str) -> None: ... def deactivate() -> None: ...