Skip to content

Commit

Permalink
Make _StrPromise and _StrOrPromise public.
Browse files Browse the repository at this point in the history
This removes the leading underscore for both of these types since they
will be needed by the users when typing "StrPromise" related things.

Since the type is stub only, it needs to be imported conditionally:

```
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from django.utils.functional import StrPromise
```

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
  • Loading branch information
PIG208 committed Sep 15, 2022
1 parent e95c760 commit d5178ed
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 135 deletions.
4 changes: 2 additions & 2 deletions django-stubs/apps/config.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from typing import Dict, Iterator, Optional, Type

from django.apps.registry import Apps
from django.db.models.base import Model
from django.utils.functional import _StrOrPromise
from django.utils.functional import StrOrPromise

MODELS_MODULE_NAME: str

Expand All @@ -12,7 +12,7 @@ class AppConfig:
module: Optional[types.ModuleType] = ...
apps: Optional[Apps] = ...
label: str = ...
verbose_name: _StrOrPromise = ...
verbose_name: StrOrPromise = ...
path: str = ...
models_module: Optional[str] = ...
models: Dict[str, Type[Model]] = ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ from django.http.response import HttpResponse, HttpResponseRedirect, JsonRespons
from django.template.response import _TemplateForResponseT
from django.urls.resolvers import URLPattern
from django.utils.datastructures import _ListOrTuple
from django.utils.functional import _StrOrPromise
from django.utils.functional import StrOrPromise
from django.utils.safestring import SafeString
from typing_extensions import Literal, TypedDict

Expand Down Expand Up @@ -297,8 +297,8 @@ class InlineModelAdmin(Generic[_ChildModelT, _ParentModelT], BaseModelAdmin[_Chi
min_num: Optional[int] = ...
max_num: Optional[int] = ...
template: str = ...
verbose_name: Optional[_StrOrPromise] = ...
verbose_name_plural: Optional[_StrOrPromise] = ...
verbose_name: Optional[StrOrPromise] = ...
verbose_name_plural: Optional[StrOrPromise] = ...
can_delete: bool = ...
show_change_link: bool = ...
classes: Optional[Sequence[str]] = ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/admin/sites.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from django.http.request import HttpRequest
from django.http.response import HttpResponse
from django.template.response import TemplateResponse
from django.urls import URLPattern, URLResolver
from django.utils.functional import LazyObject, _StrOrPromise
from django.utils.functional import LazyObject, StrOrPromise

if sys.version_info >= (3, 9):
from weakref import WeakSet
Expand Down Expand Up @@ -77,7 +77,7 @@ class AdminSite:
def i18n_javascript(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
def logout(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ...
def login(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
def _build_app_dict(self, request: HttpRequest, label: Optional[_StrOrPromise] = ...) -> Dict[str, Any]: ...
def _build_app_dict(self, request: HttpRequest, label: Optional[StrOrPromise] = ...) -> Dict[str, Any]: ...
def get_app_list(self, request: HttpRequest) -> List[Any]: ...
def index(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ...
def app_index(
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/admin/widgets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ from django.db.models.fields import _FieldChoices
from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToManyRel, ManyToOneRel
from django.forms.models import ModelChoiceIterator
from django.forms.widgets import Media, _OptAttrs
from django.utils.functional import _StrOrPromise
from django.utils.functional import StrOrPromise

class FilteredSelectMultiple(forms.SelectMultiple):
verbose_name: _StrOrPromise = ...
verbose_name: StrOrPromise = ...
is_stacked: bool = ...
def __init__(
self,
verbose_name: _StrOrPromise,
verbose_name: StrOrPromise,
is_stacked: bool,
attrs: Optional[_OptAttrs] = ...,
choices: _FieldChoices = ...,
Expand Down
10 changes: 5 additions & 5 deletions django-stubs/contrib/gis/db/models/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from typing import Any, Iterable, NamedTuple, Optional, Tuple, TypeVar, Union

from django.core.validators import _ValidatorCallable
from django.db.models.fields import Field, _ErrorMessagesT, _FieldChoices
from django.utils.functional import _StrOrPromise
from django.utils.functional import StrOrPromise

# __set__ value type
_ST = TypeVar("_ST")
Expand All @@ -20,7 +20,7 @@ def get_srid_info(srid: int, connection: Any) -> SRIDCacheEntry: ...
class BaseSpatialField(Field[_ST, _GT]):
def __init__(
self,
verbose_name: Optional[Union[_StrOrPromise, bytes]] = ...,
verbose_name: Optional[Union[StrOrPromise, bytes]] = ...,
srid: int = ...,
spatial_index: bool = ...,
*,
Expand All @@ -39,7 +39,7 @@ class BaseSpatialField(Field[_ST, _GT]):
unique_for_month: Optional[str] = ...,
unique_for_year: Optional[str] = ...,
choices: Optional[_FieldChoices] = ...,
help_text: _StrOrPromise = ...,
help_text: StrOrPromise = ...,
db_column: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
validators: Iterable[_ValidatorCallable] = ...,
Expand All @@ -66,7 +66,7 @@ class GeometryField(BaseSpatialField):
geography: Any = ...
def __init__(
self,
verbose_name: Optional[Union[_StrOrPromise, bytes]] = ...,
verbose_name: Optional[Union[StrOrPromise, bytes]] = ...,
dim: int = ...,
geography: bool = ...,
*,
Expand All @@ -89,7 +89,7 @@ class GeometryField(BaseSpatialField):
unique_for_month: Optional[str] = ...,
unique_for_year: Optional[str] = ...,
choices: Optional[_FieldChoices] = ...,
help_text: _StrOrPromise = ...,
help_text: StrOrPromise = ...,
db_column: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
validators: Iterable[_ValidatorCallable] = ...,
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/postgres/fields/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from django.db.models import Field, Transform
from django.db.models.expressions import Combinable
from django.db.models.fields import _ErrorMessagesT, _FieldChoices
from django.db.models.fields.mixins import CheckFieldDefaultMixin
from django.utils.functional import _StrOrPromise
from django.utils.functional import StrOrPromise

# __set__ value type
_ST = TypeVar("_ST")
Expand Down Expand Up @@ -43,7 +43,7 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]):
unique_for_month: Optional[str] = ...,
unique_for_year: Optional[str] = ...,
choices: Optional[_FieldChoices] = ...,
help_text: _StrOrPromise = ...,
help_text: StrOrPromise = ...,
db_column: Optional[str] = ...,
db_tablespace: Optional[str] = ...,
validators: Iterable[_ValidatorCallable] = ...,
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/core/cache/backends/db.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import Any, Dict

from django.core.cache.backends.base import BaseCache
from django.utils.functional import _StrOrPromise
from django.utils.functional import StrOrPromise

class Options:
db_table: str = ...
app_label: str = ...
model_name: str = ...
verbose_name: _StrOrPromise = ...
verbose_name_plural: _StrOrPromise = ...
verbose_name: StrOrPromise = ...
verbose_name_plural: StrOrPromise = ...
object_name: str = ...
abstract: bool = ...
managed: bool = ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/core/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union

from django.utils.functional import _StrPromise
from django.utils.functional import StrPromise
from typing_extensions import Literal

class FieldDoesNotExist(Exception): ...
Expand Down Expand Up @@ -36,7 +36,7 @@ class ValidationError(Exception):
def __init__(
self,
# Accepts arbitrarily nested data structure, mypy doesn't allow describing it accurately.
message: Union[str, _StrPromise, ValidationError, Dict[str, Any], List[Any]],
message: Union[str, StrPromise, ValidationError, Dict[str, Any], List[Any]],
code: Optional[str] = ...,
params: Optional[Dict[str, Any]] = ...,
) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/core/validators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from re import RegexFlag
from typing import Any, Callable, Collection, Dict, List, Optional, Pattern, Sequence, Sized, Tuple, Union

from django.core.files.base import File
from django.utils.functional import _StrPromise
from django.utils.functional import StrPromise

EMPTY_VALUES: Any

Expand All @@ -12,14 +12,14 @@ _ValidatorCallable = Callable[[Any], None]

class RegexValidator:
regex: _Regex = ... # Pattern[str] on instance, but may be str on class definition
message: Union[str, _StrPromise] = ...
message: Union[str, StrPromise] = ...
code: str = ...
inverse_match: bool = ...
flags: int = ...
def __init__(
self,
regex: Optional[_Regex] = ...,
message: Union[str, _StrPromise, None] = ...,
message: Union[str, StrPromise, None] = ...,
code: Optional[str] = ...,
inverse_match: Optional[bool] = ...,
flags: Optional[RegexFlag] = ...,
Expand Down
Loading

0 comments on commit d5178ed

Please sign in to comment.