Skip to content

Commit

Permalink
Add StrPromise and StrOrPromise aliases to django_stubs_ext.
Browse files Browse the repository at this point in the history
We re-export StrPromise and StrOrPromise implicitly making it 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>
  • Loading branch information
PIG208 committed Sep 16, 2022
1 parent 83bba91 commit 15a0032
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion django_stubs_ext/django_stubs_ext/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
4 changes: 4 additions & 0 deletions django_stubs_ext/django_stubs_ext/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

if typing.TYPE_CHECKING:
from django.db.models.query import _T, _QuerySet, _Row
from django.utils.functional import StrOrPromise, StrPromise

ValuesQuerySet = _QuerySet[_T, _Row]
else:
from django.db.models.query import QuerySet
from django.utils.functional import Promise, StrOrPromise

ValuesQuerySet = QuerySet
StrPromise = Promise
StrOrPromise = typing.Union[str, Promise]

0 comments on commit 15a0032

Please sign in to comment.