Skip to content

Commit 59bfd6f

Browse files
committed
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 <[email protected]>
1 parent e95c760 commit 59bfd6f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
from .aliases import StrOrPromise, StrPromise
12
from .aliases import ValuesQuerySet as ValuesQuerySet
23
from .annotations import Annotations as Annotations
34
from .annotations import WithAnnotations as WithAnnotations
45
from .patch import monkeypatch as monkeypatch
56
from .types import AnyAttrAllowed as AnyAttrAllowed
67

7-
__all__ = ["monkeypatch", "ValuesQuerySet", "WithAnnotations", "Annotations", "AnyAttrAllowed"]
8+
__all__ = [
9+
"monkeypatch",
10+
"ValuesQuerySet",
11+
"WithAnnotations",
12+
"Annotations",
13+
"AnyAttrAllowed",
14+
"StrPromise",
15+
"StrOrPromise",
16+
]

django_stubs_ext/django_stubs_ext/aliases.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
if typing.TYPE_CHECKING:
44
from django.db.models.query import _T, _QuerySet, _Row
5+
from django.utils.functional import _StrOrPromise as StrOrPromise
6+
from django.utils.functional import _StrPromise as StrPromise
57

68
ValuesQuerySet = _QuerySet[_T, _Row]
79
else:
810
from django.db.models.query import QuerySet
11+
from django.utils.functional import Promise as StrPromise
912

1013
ValuesQuerySet = QuerySet
14+
StrOrPromise = typing.Union[str, StrPromise]

0 commit comments

Comments
 (0)