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 explicitly 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 21ce4fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion django_stubs_ext/django_stubs_ext/__init__.py
@@ -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",
]
6 changes: 6 additions & 0 deletions django_stubs_ext/django_stubs_ext/aliases.py
Expand Up @@ -2,9 +2,15 @@

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

ValuesQuerySet = _QuerySet[_T, _Row]
StrOrPromise = StrOrPromise
StrPromise = StrPromise
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 21ce4fe

Please sign in to comment.