Broaden type annotation for verbose_name(_plural) to accept lazystr. (#1139)

* Broaden type annotation for verbose_name(_plural) to accept lazystr.

Fixes #1137.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Broaden type annotation for help_text to accept lazystr.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Broaden type annotation for ValidationError to accept lazystr.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Broaden type annotation for label to accept lazystr.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Add StrPromise and StrOrPromise aliases to django_stubs_ext.

We make StrPromise and StrOrPromise available via django_stubs_ext so
that conditional imports with TYPE_CHECKING is not required.
These aliases fall back to Promise or Union[str, Promise]
when not TYPE_CHECKING.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
PIG208
2022-09-19 10:01:44 -04:00
committed by GitHub
parent a2a3543198
commit 9a41aa63ba
19 changed files with 138 additions and 104 deletions

View File

@@ -1,7 +1,16 @@
from .aliases import StrOrPromise, StrPromise
from .aliases import ValuesQuerySet as ValuesQuerySet
from .annotations import Annotations as Annotations
from .annotations import WithAnnotations as WithAnnotations
from .patch import monkeypatch as monkeypatch
from .types import AnyAttrAllowed as AnyAttrAllowed
__all__ = ["monkeypatch", "ValuesQuerySet", "WithAnnotations", "Annotations", "AnyAttrAllowed"]
__all__ = [
"monkeypatch",
"ValuesQuerySet",
"WithAnnotations",
"Annotations",
"AnyAttrAllowed",
"StrPromise",
"StrOrPromise",
]

View File

@@ -2,9 +2,15 @@ import typing
if typing.TYPE_CHECKING:
from django.db.models.query import _T, _QuerySet, _Row
from django.utils.functional import _StrOrPromise as StrOrPromise
from django.utils.functional import _StrPromise as StrPromise
ValuesQuerySet = _QuerySet[_T, _Row]
else:
from django.db.models.query import QuerySet
from django.utils.functional import Promise as StrPromise
ValuesQuerySet = QuerySet
StrOrPromise = typing.Union[str, StrPromise]
__all__ = ["StrOrPromise", "StrPromise", "ValuesQuerySet"]