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 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>
  • Loading branch information
PIG208 committed Sep 18, 2022
1 parent e95c760 commit 1ba1dfd
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 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"]

0 comments on commit 1ba1dfd

Please sign in to comment.