mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-20 10:51:16 +08:00
Add Django 3.0 testing to CI (#246)
* add Django 3.0 testing to CI * remove importlib_metadata usage * conditionally load choices module for tests
This commit is contained in:
@@ -129,3 +129,5 @@ from .constraints import (
|
||||
CheckConstraint as CheckConstraint,
|
||||
UniqueConstraint as UniqueConstraint,
|
||||
)
|
||||
|
||||
from .enums import Choices as Choices, IntegerChoices as IntegerChoices, TextChoices as TextChoices
|
||||
|
||||
30
django-stubs/db/models/enums.pyi
Normal file
30
django-stubs/db/models/enums.pyi
Normal file
@@ -0,0 +1,30 @@
|
||||
import enum
|
||||
from typing import Any, List, Tuple
|
||||
|
||||
class ChoicesMeta(enum.EnumMeta):
|
||||
names: List[str] = ...
|
||||
choices: List[Tuple[Any, str]] = ...
|
||||
labels: List[str] = ...
|
||||
values: List[Any] = ...
|
||||
def __contains__(self, item: Any) -> bool: ...
|
||||
|
||||
class Choices(enum.Enum, metaclass=ChoicesMeta):
|
||||
def __str__(self): ...
|
||||
|
||||
# fake
|
||||
class _IntegerChoicesMeta(ChoicesMeta):
|
||||
names: List[str] = ...
|
||||
choices: List[Tuple[int, str]] = ...
|
||||
labels: List[str] = ...
|
||||
values: List[int] = ...
|
||||
|
||||
class IntegerChoices(int, Choices, metaclass=_IntegerChoicesMeta): ...
|
||||
|
||||
# fake
|
||||
class _TextChoicesMeta(ChoicesMeta):
|
||||
names: List[str] = ...
|
||||
choices: List[Tuple[str, str]] = ...
|
||||
labels: List[str] = ...
|
||||
values: List[str] = ...
|
||||
|
||||
class TextChoices(str, Choices, metaclass=_TextChoicesMeta): ...
|
||||
@@ -108,7 +108,8 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
|
||||
def db_parameters(self, connection: Any) -> Dict[str, str]: ...
|
||||
def get_prep_value(self, value: Any) -> Any: ...
|
||||
def get_internal_type(self) -> str: ...
|
||||
def formfield(self, **kwargs) -> FormField: ...
|
||||
# TODO: plugin support
|
||||
def formfield(self, **kwargs) -> Any: ...
|
||||
def save_form_data(self, instance: Model, data: Any) -> None: ...
|
||||
def contribute_to_class(self, cls: Type[Model], name: str, private_only: bool = ...) -> None: ...
|
||||
def to_python(self, value: Any) -> Any: ...
|
||||
@@ -361,20 +362,20 @@ class UUIDField(Field[_ST, _GT]):
|
||||
_pyi_private_get_type: uuid.UUID
|
||||
|
||||
class FilePathField(Field[_ST, _GT]):
|
||||
path: str = ...
|
||||
match: Optional[Any] = ...
|
||||
path: Any = ...
|
||||
match: Optional[str] = ...
|
||||
recursive: bool = ...
|
||||
allow_files: bool = ...
|
||||
allow_folders: bool = ...
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
name: Optional[str] = ...,
|
||||
path: str = ...,
|
||||
match: Optional[Any] = ...,
|
||||
path: Union[str, Callable[..., str]] = ...,
|
||||
match: Optional[str] = ...,
|
||||
recursive: bool = ...,
|
||||
allow_files: bool = ...,
|
||||
allow_folders: bool = ...,
|
||||
verbose_name: Optional[str] = ...,
|
||||
name: Optional[str] = ...,
|
||||
primary_key: bool = ...,
|
||||
max_length: int = ...,
|
||||
unique: bool = ...,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Iterable, List, Optional, Tuple, Type, TypeVar, Union, overload
|
||||
|
||||
from django.core.files.base import File
|
||||
@@ -39,11 +40,10 @@ class FileField(Field):
|
||||
upload_to: Union[str, Callable] = ...
|
||||
def __init__(
|
||||
self,
|
||||
upload_to: Union[str, Callable, Path] = ...,
|
||||
storage: Optional[Storage] = ...,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
name: Optional[str] = ...,
|
||||
upload_to: Union[str, Callable] = ...,
|
||||
storage: Optional[Storage] = ...,
|
||||
primary_key: bool = ...,
|
||||
max_length: Optional[int] = ...,
|
||||
unique: bool = ...,
|
||||
blank: bool = ...,
|
||||
|
||||
@@ -108,6 +108,8 @@ class Options(Generic[_M]):
|
||||
def managers(self) -> List[Manager]: ...
|
||||
@property
|
||||
def managers_map(self) -> Dict[str, Manager]: ...
|
||||
@property
|
||||
def db_returning_fields(self) -> List[Field]: ...
|
||||
def get_field(self, field_name: Union[Callable, str]) -> Field: ...
|
||||
def get_base_chain(self, model: Type[Model]) -> List[Type[Model]]: ...
|
||||
def get_parent_list(self) -> List[Type[Model]]: ...
|
||||
|
||||
@@ -42,6 +42,7 @@ class Q(tree.Node):
|
||||
|
||||
class DeferredAttribute:
|
||||
field_name: str = ...
|
||||
field: Field
|
||||
def __init__(self, field_name: str) -> None: ...
|
||||
|
||||
class RegisterLookupMixin:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import collections
|
||||
from collections import OrderedDict, namedtuple
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Type, Union
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Type, Union, Iterable
|
||||
|
||||
from django.db.models.lookups import Lookup, Transform
|
||||
from django.db.models.query_utils import PathInfo, RegisterLookupMixin
|
||||
@@ -155,19 +155,19 @@ class Query:
|
||||
def add_ordering(self, *ordering: Any) -> None: ...
|
||||
def clear_ordering(self, force_empty: bool) -> None: ...
|
||||
def set_group_by(self) -> None: ...
|
||||
def add_select_related(self, fields: Tuple[str]) -> None: ...
|
||||
def add_select_related(self, fields: Iterable[str]) -> None: ...
|
||||
def add_extra(
|
||||
self,
|
||||
select: Optional[Union[Dict[str, int], Dict[str, str], OrderedDict]],
|
||||
select_params: Optional[Union[List[int], List[str], Tuple[int]]],
|
||||
where: Optional[List[str]],
|
||||
params: Optional[List[str]],
|
||||
tables: Optional[List[str]],
|
||||
order_by: Optional[Union[List[str], Tuple[str]]],
|
||||
select: Optional[Dict[str, Any]],
|
||||
select_params: Optional[Iterable[Any]],
|
||||
where: Optional[Sequence[str]],
|
||||
params: Optional[Sequence[str]],
|
||||
tables: Optional[Sequence[str]],
|
||||
order_by: Optional[Sequence[str]],
|
||||
) -> None: ...
|
||||
def clear_deferred_loading(self) -> None: ...
|
||||
def add_deferred_loading(self, field_names: Tuple[str]) -> None: ...
|
||||
def add_immediate_loading(self, field_names: Tuple[str]) -> None: ...
|
||||
def add_deferred_loading(self, field_names: Iterable[str]) -> None: ...
|
||||
def add_immediate_loading(self, field_names: Iterable[str]) -> None: ...
|
||||
def get_loaded_field_names(self) -> Dict[Type[Model], Set[str]]: ...
|
||||
def get_loaded_field_names_cb(
|
||||
self, target: Dict[Type[Model], Set[str]], model: Type[Model], fields: Set[Field]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from os.path import abspath
|
||||
from pathlib import Path
|
||||
from typing import Any, Union
|
||||
|
||||
abspathu = abspath
|
||||
@@ -7,3 +8,4 @@ def upath(path: Any): ...
|
||||
def npath(path: Any): ...
|
||||
def safe_join(base: Union[bytes, str], *paths: Any) -> str: ...
|
||||
def symlinks_supported() -> Any: ...
|
||||
def to_path(value: Union[Path, str]) -> Path: ...
|
||||
|
||||
@@ -5,6 +5,7 @@ from django.http.response import HttpResponse
|
||||
|
||||
class RemovedInDjango30Warning(PendingDeprecationWarning): ...
|
||||
class RemovedInDjango31Warning(PendingDeprecationWarning): ...
|
||||
class RemovedInDjango40Warning(PendingDeprecationWarning): ...
|
||||
class RemovedInNextVersionWarning(DeprecationWarning): ...
|
||||
|
||||
class warn_about_renamed_method:
|
||||
|
||||
@@ -25,6 +25,9 @@ def urlsafe_base64_decode(s: Union[bytes, str]) -> bytes: ...
|
||||
def parse_etags(etag_str: str) -> List[str]: ...
|
||||
def quote_etag(etag_str: str) -> str: ...
|
||||
def is_same_domain(host: str, pattern: str) -> bool: ...
|
||||
def url_has_allowed_host_and_scheme(
|
||||
url: Optional[str], allowed_hosts: Optional[Union[str, Iterable[str]]], require_https: bool = ...
|
||||
) -> bool: ...
|
||||
def is_safe_url(
|
||||
url: Optional[str], allowed_hosts: Optional[Union[str, Iterable[str]]], require_https: bool = ...
|
||||
) -> bool: ...
|
||||
|
||||
@@ -63,4 +63,4 @@ class ExceptionReporter:
|
||||
): ...
|
||||
|
||||
def technical_404_response(request: HttpRequest, exception: Http404) -> HttpResponse: ...
|
||||
def default_urlconf(request: HttpRequest) -> HttpResponse: ...
|
||||
def default_urlconf(request: Optional[HttpResponse]) -> HttpResponse: ...
|
||||
|
||||
Reference in New Issue
Block a user