Skip to content

Commit 1ba1dfd

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 1ba1dfd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 10 additions & 1 deletion
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
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]
15+
16+
__all__ = ["StrOrPromise", "StrPromise"]

0 commit comments

Comments
 (0)