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 17, 2022
1 parent e95c760 commit 159327e
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

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

0 comments on commit 159327e

Please sign in to comment.