mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 22:11:54 +08:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5dd6eccdb5 | ||
|
|
fd06816cbb | ||
|
|
aeb435c8b3 | ||
|
|
13d19017b7 | ||
|
|
28a3f126ee | ||
|
|
304cb19de6 | ||
|
|
c57f4f7152 | ||
|
|
8a826fee1e | ||
|
|
37d85c2ca6 | ||
|
|
71fb0432f3 | ||
|
|
9288c34648 | ||
|
|
70050f28b9 | ||
|
|
4338c17970 | ||
|
|
91f789c38c | ||
|
|
0f5b45fba1 | ||
|
|
5b455b729a | ||
|
|
5c6be7ad12 | ||
|
|
5d0ee40ada | ||
|
|
77f15d7478 | ||
|
|
4f83d8d1bb | ||
|
|
b1a04d2f7d | ||
|
|
7c57143310 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,4 +7,5 @@ out/
|
||||
.mypy_cache/
|
||||
django-sources
|
||||
build/
|
||||
dist/
|
||||
dist/
|
||||
pip-wheel-metadata/
|
||||
@@ -44,6 +44,9 @@ django_settings = mysettings.local
|
||||
# if True, all unknown settings in django.conf.settings will fallback to Any,
|
||||
# specify it if your settings are loaded dynamically to avoid false positives
|
||||
ignore_missing_settings = True
|
||||
|
||||
# if True, unknown attributes on Model instances won't produce errors
|
||||
ignore_missing_model_attributes = True
|
||||
```
|
||||
|
||||
## To get help
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
from typing import Any
|
||||
from typing import Any, NamedTuple
|
||||
from .utils.version import get_version as get_version
|
||||
|
||||
VERSION: Any
|
||||
__version__: str
|
||||
|
||||
def setup(set_prefix: bool = ...) -> None: ...
|
||||
|
||||
# Used by mypy_django_plugin when returning a QuerySet row that is a NamedTuple where the field names are unknown
|
||||
class _NamedTupleAnyAttr(NamedTuple):
|
||||
def __getattr__(self, item: str) -> Any: ...
|
||||
def __setattr__(self, item: str, value: Any) -> None: ...
|
||||
|
||||
@@ -2,10 +2,14 @@ from typing import Any
|
||||
|
||||
from django.utils.functional import LazyObject
|
||||
|
||||
# explicit dependency on standard settings to make it loaded
|
||||
from . import global_settings
|
||||
|
||||
ENVIRONMENT_VARIABLE: str = ...
|
||||
|
||||
# required for plugin to be able to distinguish this specific instance of LazySettings from others
|
||||
class _DjangoConfLazyObject(LazyObject): ...
|
||||
class _DjangoConfLazyObject(LazyObject):
|
||||
def __getattr__(self, item: Any) -> Any: ...
|
||||
|
||||
class LazySettings(_DjangoConfLazyObject):
|
||||
configured: bool
|
||||
|
||||
@@ -5,14 +5,11 @@ by the DJANGO_SETTINGS_MODULE environment variable.
|
||||
|
||||
# This is defined here as a do-nothing function because we can't import
|
||||
# django.utils.translation -- that module depends on the settings.
|
||||
from typing import Any, Dict, List, Optional, Pattern, Tuple, Protocol, Union, Callable, TYPE_CHECKING, Sequence
|
||||
from typing import Any, Dict, List, Optional, Pattern, Protocol, Sequence, Tuple, Union
|
||||
|
||||
####################
|
||||
# CORE #
|
||||
####################
|
||||
if TYPE_CHECKING:
|
||||
from django.db.models.base import Model
|
||||
|
||||
DEBUG: bool = ...
|
||||
|
||||
# Whether the framework should propagate raw exceptions rather than catching
|
||||
@@ -153,7 +150,7 @@ FORCE_SCRIPT_NAME = None
|
||||
# ]
|
||||
DISALLOWED_USER_AGENTS: List[Pattern] = ...
|
||||
|
||||
ABSOLUTE_URL_OVERRIDES: Dict[str, Callable[[Model], str]] = ...
|
||||
ABSOLUTE_URL_OVERRIDES: Dict[str, Any] = ...
|
||||
|
||||
# List of compiled regular expression objects representing URLs that need not
|
||||
# be reported by BrokenLinkEmailsMiddleware. Here are a few examples:
|
||||
|
||||
@@ -1,25 +1,6 @@
|
||||
from typing import Any
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
class SimpleAdminConfig(AppConfig):
|
||||
apps: None
|
||||
label: str
|
||||
models: None
|
||||
models_module: None
|
||||
module: Any
|
||||
path: str
|
||||
default_site: str = ...
|
||||
name: str = ...
|
||||
verbose_name: Any = ...
|
||||
def ready(self) -> None: ...
|
||||
|
||||
class AdminConfig(SimpleAdminConfig):
|
||||
apps: None
|
||||
label: str
|
||||
models: None
|
||||
models_module: None
|
||||
module: Any
|
||||
name: str
|
||||
path: str
|
||||
def ready(self) -> None: ...
|
||||
class AdminConfig(SimpleAdminConfig): ...
|
||||
|
||||
@@ -1,33 +1,7 @@
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class AdminAuthenticationForm(AuthenticationForm):
|
||||
auto_id: str
|
||||
data: Dict[str, str]
|
||||
empty_permitted: bool
|
||||
error_class: type
|
||||
fields: Dict[Any, Any]
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[Any, Any]
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
request: None
|
||||
user_cache: None
|
||||
error_messages: Any = ...
|
||||
required_css_class: str = ...
|
||||
def confirm_login_allowed(self, user: User) -> None: ...
|
||||
|
||||
class AdminPasswordChangeForm(PasswordChangeForm):
|
||||
auto_id: str
|
||||
data: Dict[Any, Any]
|
||||
empty_permitted: bool
|
||||
error_class: type
|
||||
fields: Dict[Any, Any]
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[Any, Any]
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
user: Any
|
||||
required_css_class: str = ...
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
import collections
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, Type
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
|
||||
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import AdminPasswordChangeForm
|
||||
from django.db.models.fields import AutoField
|
||||
from django.forms.utils import ErrorDict, ErrorList
|
||||
from django.forms.boundfield import BoundField
|
||||
from django.forms.utils import ErrorDict
|
||||
from django.forms.widgets import Media, Widget
|
||||
from django.utils.safestring import SafeText
|
||||
|
||||
from django.forms.boundfield import BoundField
|
||||
from django import forms
|
||||
from django.db.models.fields import AutoField
|
||||
|
||||
ACTION_CHECKBOX_NAME: str
|
||||
|
||||
class ActionForm(forms.Form):
|
||||
auto_id: None
|
||||
data: Dict[Any, Any]
|
||||
empty_permitted: bool
|
||||
error_class: Type[ErrorList]
|
||||
fields: collections.OrderedDict
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[Any, Any]
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
action: Any = ...
|
||||
select_across: Any = ...
|
||||
|
||||
@@ -36,8 +26,8 @@ class AdminForm:
|
||||
form: AdminPasswordChangeForm,
|
||||
fieldsets: List[Tuple[None, Dict[str, List[str]]]],
|
||||
prepopulated_fields: Dict[Any, Any],
|
||||
readonly_fields: None = ...,
|
||||
model_admin: None = ...,
|
||||
readonly_fields: Any = ...,
|
||||
model_admin: Any = ...,
|
||||
) -> None: ...
|
||||
def __iter__(self) -> Iterator[Fieldset]: ...
|
||||
@property
|
||||
@@ -137,7 +127,6 @@ class InlineAdminFormSet:
|
||||
|
||||
class InlineAdminForm(AdminForm):
|
||||
formset: Any = ...
|
||||
model_admin: Any = ...
|
||||
original: Any = ...
|
||||
show_url: Any = ...
|
||||
absolute_url: Any = ...
|
||||
@@ -152,7 +141,6 @@ class InlineAdminForm(AdminForm):
|
||||
model_admin: Optional[Any] = ...,
|
||||
view_on_site_url: Optional[Any] = ...,
|
||||
) -> None: ...
|
||||
def __iter__(self) -> Iterator[InlineFieldset]: ...
|
||||
def needs_explicit_pk_field(self) -> Union[bool, AutoField]: ...
|
||||
def pk_field(self) -> AdminField: ...
|
||||
def fk_field(self) -> AdminField: ...
|
||||
@@ -162,9 +150,6 @@ class InlineAdminForm(AdminForm):
|
||||
class InlineFieldset(Fieldset):
|
||||
formset: Any = ...
|
||||
def __init__(self, formset: Any, *args: Any, **kwargs: Any) -> None: ...
|
||||
def __iter__(self) -> Iterator[Fieldline]: ...
|
||||
|
||||
class AdminErrorList(forms.utils.ErrorList):
|
||||
data: List[Any]
|
||||
error_class: str
|
||||
def __init__(self, form: Any, inline_formsets: Any) -> None: ...
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from django.contrib.admin.options import ModelAdmin
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models.query import QuerySet
|
||||
from django.http.response import JsonResponse
|
||||
from django.views.generic.list import BaseListView
|
||||
|
||||
class AutocompleteJsonView(BaseListView):
|
||||
paginate_by: int = ...
|
||||
model_admin: ModelAdmin = ...
|
||||
term: Any = ...
|
||||
paginator_class: Any = ...
|
||||
object_list: Any = ...
|
||||
def get(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> JsonResponse: ...
|
||||
def get_paginator(self, *args: Any, **kwargs: Any) -> Paginator: ...
|
||||
def get_queryset(self) -> QuerySet: ...
|
||||
def has_perm(self, request: WSGIRequest, obj: None = ...) -> bool: ...
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
|
||||
from typing import Any, Dict, List, Optional, Set, Tuple, Union
|
||||
from uuid import UUID
|
||||
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToOneRel
|
||||
from django.forms.models import ModelChoiceIterator
|
||||
from django.forms.widgets import ChoiceWidget, Media
|
||||
|
||||
from django import forms
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToOneRel, ManyToManyRel
|
||||
from django.db.models.query_utils import Q
|
||||
from django.forms.fields import Field
|
||||
from django.forms.widgets import ChoiceWidget, Media, Widget, DateTimeBaseInput
|
||||
from django.http.request import QueryDict
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
|
||||
class FilteredSelectMultiple(forms.SelectMultiple):
|
||||
@property
|
||||
@@ -20,109 +14,34 @@ class FilteredSelectMultiple(forms.SelectMultiple):
|
||||
verbose_name: Any = ...
|
||||
is_stacked: Any = ...
|
||||
def __init__(self, verbose_name: str, is_stacked: bool, attrs: None = ..., choices: Tuple = ...) -> None: ...
|
||||
def get_context(
|
||||
self, name: str, value: Union[List[Any], str], attrs: Optional[Dict[str, str]]
|
||||
) -> Dict[
|
||||
str,
|
||||
Union[
|
||||
Dict[
|
||||
str,
|
||||
Union[
|
||||
Dict[str, Union[int, str]],
|
||||
List[Tuple[None, List[Dict[str, Union[Dict[Any, Any], int, str]]], int]],
|
||||
bool,
|
||||
str,
|
||||
],
|
||||
],
|
||||
Dict[str, Union[Dict[str, Union[int, str]], List[str], bool, str]],
|
||||
],
|
||||
]: ...
|
||||
|
||||
class AdminDateWidget(forms.DateInput):
|
||||
attrs: Dict[str, str]
|
||||
input_type: str
|
||||
@property
|
||||
def media(self) -> Media: ...
|
||||
def __init__(self, attrs: Optional[Dict[str, Union[int, str]]] = ..., format: None = ...) -> None: ...
|
||||
|
||||
class AdminTimeWidget(forms.TimeInput):
|
||||
attrs: Dict[str, str]
|
||||
input_type: str
|
||||
@property
|
||||
def media(self) -> Media: ...
|
||||
def __init__(self, attrs: Optional[Dict[str, Union[int, str]]] = ..., format: None = ...) -> None: ...
|
||||
|
||||
class AdminSplitDateTime(forms.SplitDateTimeWidget):
|
||||
attrs: Dict[Any, Any]
|
||||
widgets: List[DateTimeBaseInput]
|
||||
template_name: str = ...
|
||||
def __init__(self, attrs: None = ...) -> None: ...
|
||||
def get_context(
|
||||
self, name: str, value: Optional[Union[List[str], datetime]], attrs: Optional[Dict[str, Union[bool, str]]]
|
||||
) -> Dict[
|
||||
str,
|
||||
Union[
|
||||
Dict[
|
||||
str,
|
||||
Optional[
|
||||
Union[
|
||||
Dict[str, Union[bool, str]],
|
||||
List[Dict[str, Optional[Union[Dict[str, Union[bool, str]], bool, str]]]],
|
||||
bool,
|
||||
str,
|
||||
]
|
||||
],
|
||||
],
|
||||
str,
|
||||
],
|
||||
]: ...
|
||||
class AdminSplitDateTime(forms.SplitDateTimeWidget): ...
|
||||
class AdminRadioSelect(forms.RadioSelect): ...
|
||||
class AdminFileWidget(forms.ClearableFileInput): ...
|
||||
|
||||
class AdminRadioSelect(forms.RadioSelect):
|
||||
attrs: Dict[str, str]
|
||||
template_name: str = ...
|
||||
|
||||
class AdminFileWidget(forms.ClearableFileInput):
|
||||
attrs: Dict[Any, Any]
|
||||
template_name: str = ...
|
||||
|
||||
def url_params_from_lookup_dict(
|
||||
lookups: Union[
|
||||
Dict[str, Callable], Dict[str, List[str]], Dict[str, Tuple[str, str]], Dict[str, bool], Dict[str, str], Q
|
||||
]
|
||||
) -> Dict[str, str]: ...
|
||||
def url_params_from_lookup_dict(lookups: Any) -> Dict[str, str]: ...
|
||||
|
||||
class ForeignKeyRawIdWidget(forms.TextInput):
|
||||
attrs: Dict[Any, Any]
|
||||
template_name: str = ...
|
||||
rel: ManyToOneRel = ...
|
||||
admin_site: AdminSite = ...
|
||||
db: None = ...
|
||||
def __init__(self, rel: ForeignObjectRel, admin_site: AdminSite, attrs: None = ..., using: None = ...) -> None: ...
|
||||
def get_context(
|
||||
self, name: str, value: Optional[Union[List[int], int, str, UUID]], attrs: Optional[Dict[str, Union[bool, str]]]
|
||||
) -> Dict[str, Union[Dict[str, Optional[Union[Dict[str, Union[bool, str]], bool, str]]], str]]: ...
|
||||
def base_url_parameters(self) -> Dict[str, str]: ...
|
||||
def url_parameters(self) -> Dict[str, str]: ...
|
||||
def label_and_url_for_value(self, value: Union[int, str, UUID]) -> Tuple[str, str]: ...
|
||||
|
||||
class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
|
||||
admin_site: AdminSite
|
||||
attrs: Dict[Any, Any]
|
||||
db: None
|
||||
rel: ManyToManyRel
|
||||
template_name: str = ...
|
||||
def get_context(
|
||||
self, name: str, value: Optional[List[int]], attrs: Optional[Dict[str, str]]
|
||||
) -> Dict[str, Union[Dict[str, Union[Dict[str, str], bool, str]], str]]: ...
|
||||
def url_parameters(self) -> Dict[Any, Any]: ...
|
||||
def label_and_url_for_value(self, value: List[int]) -> Tuple[str, str]: ...
|
||||
def value_from_datadict(self, data: QueryDict, files: MultiValueDict, name: str) -> None: ...
|
||||
def format_value(self, value: Optional[List[int]]) -> str: ...
|
||||
class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): ...
|
||||
|
||||
class RelatedFieldWidgetWrapper(forms.Widget):
|
||||
template_name: str = ...
|
||||
needs_multipart_form: bool = ...
|
||||
attrs: Dict[Any, Any] = ...
|
||||
choices: ModelChoiceIterator = ...
|
||||
widget: AutocompleteSelect = ...
|
||||
rel: ManyToOneRel = ...
|
||||
@@ -141,54 +60,19 @@ class RelatedFieldWidgetWrapper(forms.Widget):
|
||||
can_delete_related: bool = ...,
|
||||
can_view_related: bool = ...,
|
||||
) -> None: ...
|
||||
def __deepcopy__(
|
||||
self, memo: Dict[int, Union[List[Union[Field, Widget]], OrderedDict, Field, Widget]]
|
||||
) -> RelatedFieldWidgetWrapper: ...
|
||||
@property
|
||||
def is_hidden(self) -> bool: ...
|
||||
@property
|
||||
def media(self) -> Media: ...
|
||||
def get_related_url(self, info: Tuple[str, str], action: str, *args: Any) -> str: ...
|
||||
def get_context(
|
||||
self, name: str, value: Optional[Union[int, str]], attrs: Optional[Dict[str, Union[bool, str]]]
|
||||
) -> Dict[str, Union[bool, str]]: ...
|
||||
def value_from_datadict(
|
||||
self, data: QueryDict, files: MultiValueDict, name: str
|
||||
) -> Optional[Union[List[str], str]]: ...
|
||||
def value_omitted_from_data(self, data: Dict[Any, Any], files: Dict[Any, Any], name: str) -> bool: ...
|
||||
def id_for_label(self, id_: str) -> str: ...
|
||||
|
||||
class AdminTextareaWidget(forms.Textarea):
|
||||
attrs: Dict[str, str]
|
||||
def __init__(self, attrs: None = ...) -> None: ...
|
||||
|
||||
class AdminTextInputWidget(forms.TextInput):
|
||||
attrs: Dict[str, str]
|
||||
input_type: str
|
||||
def __init__(self, attrs: None = ...) -> None: ...
|
||||
|
||||
class AdminEmailInputWidget(forms.EmailInput):
|
||||
attrs: Dict[str, str]
|
||||
input_type: str
|
||||
def __init__(self, attrs: None = ...) -> None: ...
|
||||
|
||||
class AdminURLFieldWidget(forms.URLInput):
|
||||
attrs: Dict[str, str]
|
||||
input_type: str
|
||||
template_name: str = ...
|
||||
def __init__(self, attrs: None = ...) -> None: ...
|
||||
def get_context(
|
||||
self, name: str, value: Optional[str], attrs: Optional[Dict[str, str]]
|
||||
) -> Dict[str, Union[Dict[str, Optional[Union[Dict[str, str], bool, str]]], str]]: ...
|
||||
class AdminTextareaWidget(forms.Textarea): ...
|
||||
class AdminTextInputWidget(forms.TextInput): ...
|
||||
class AdminEmailInputWidget(forms.EmailInput): ...
|
||||
class AdminURLFieldWidget(forms.URLInput): ...
|
||||
|
||||
class AdminIntegerFieldWidget(forms.NumberInput):
|
||||
attrs: Dict[str, str]
|
||||
input_type: str
|
||||
class_name: str = ...
|
||||
def __init__(self, attrs: None = ...) -> None: ...
|
||||
|
||||
class AdminBigIntegerFieldWidget(AdminIntegerFieldWidget):
|
||||
class_name: str = ...
|
||||
class AdminBigIntegerFieldWidget(AdminIntegerFieldWidget): ...
|
||||
|
||||
SELECT2_TRANSLATIONS: Any
|
||||
|
||||
@@ -208,12 +92,6 @@ class AutocompleteMixin:
|
||||
using: None = ...,
|
||||
) -> None: ...
|
||||
def get_url(self) -> str: ...
|
||||
def build_attrs(
|
||||
self, base_attrs: Dict[str, str], extra_attrs: Optional[Dict[str, Union[bool, str]]] = ...
|
||||
) -> Dict[str, Union[bool, str]]: ...
|
||||
def optgroups(
|
||||
self, name: str, value: List[str], attr: Dict[str, Union[bool, str]] = ...
|
||||
) -> List[Tuple[None, List[Dict[str, Union[Dict[str, bool], Set[str], int, str]]], int]]: ...
|
||||
@property
|
||||
def media(self) -> Media: ...
|
||||
|
||||
|
||||
@@ -1,55 +1,18 @@
|
||||
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
||||
from typing import Any
|
||||
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.db.models.fields import Field
|
||||
from django.db.models.fields.related import ManyToManyField
|
||||
from django.db.models.options import Options
|
||||
from django.forms.models import ModelMultipleChoiceField
|
||||
from django.forms.fields import Field as FormField
|
||||
from django.forms.widgets import Widget
|
||||
from django.http.response import HttpResponse
|
||||
from django.urls.resolvers import URLPattern
|
||||
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
|
||||
csrf_protect_m: Any
|
||||
sensitive_post_parameters_m: Any
|
||||
|
||||
class GroupAdmin(admin.ModelAdmin):
|
||||
admin_site: AdminSite
|
||||
formfield_overrides: Any
|
||||
model: Type[Group]
|
||||
opts: Options
|
||||
search_fields: Any = ...
|
||||
ordering: Any = ...
|
||||
filter_horizontal: Any = ...
|
||||
def formfield_for_manytomany(
|
||||
self, db_field: ManyToManyField, request: WSGIRequest = ..., **kwargs: Any
|
||||
) -> ModelMultipleChoiceField: ...
|
||||
class GroupAdmin(admin.ModelAdmin): ...
|
||||
|
||||
class UserAdmin(admin.ModelAdmin):
|
||||
admin_site: AdminSite
|
||||
formfield_overrides: Dict[Type[Field], Dict[str, Type[Union[FormField, Widget]]]]
|
||||
model: Type[User]
|
||||
opts: Options
|
||||
add_form_template: str = ...
|
||||
change_user_password_template: Any = ...
|
||||
fieldsets: Any = ...
|
||||
add_fieldsets: Any = ...
|
||||
form: Any = ...
|
||||
add_form: Any = ...
|
||||
change_password_form: Any = ...
|
||||
list_display: Any = ...
|
||||
list_filter: Any = ...
|
||||
search_fields: Any = ...
|
||||
ordering: Any = ...
|
||||
filter_horizontal: Any = ...
|
||||
def get_fieldsets(self, request: WSGIRequest, obj: None = ...) -> Tuple[Tuple[None, Dict[str, Tuple[str]]]]: ...
|
||||
def get_form(self, request: Any, obj: Optional[Any] = ..., **kwargs: Any): ...
|
||||
def get_urls(self) -> List[URLPattern]: ...
|
||||
def lookup_allowed(self, lookup: str, value: str) -> bool: ...
|
||||
def add_view(self, request: WSGIRequest, form_url: str = ..., extra_context: None = ...) -> Any: ...
|
||||
def user_change_password(self, request: WSGIRequest, id: str, form_url: str = ...) -> HttpResponse: ...
|
||||
def response_add(self, request: WSGIRequest, obj: User, post_url_continue: None = ...) -> HttpResponse: ...
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
from .checks import check_models_permissions, check_user_model
|
||||
from .management import create_permissions
|
||||
from .signals import user_logged_in
|
||||
|
||||
class AuthConfig(AppConfig):
|
||||
apps: None
|
||||
label: str
|
||||
models: None
|
||||
models_module: None
|
||||
module: Any
|
||||
path: str
|
||||
name: str = ...
|
||||
verbose_name: Any = ...
|
||||
def ready(self) -> None: ...
|
||||
class AuthConfig(AppConfig): ...
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
from typing import Any, List, Optional
|
||||
from typing import Any, List
|
||||
|
||||
from django.core.checks.messages import CheckMessage
|
||||
|
||||
from .management import _get_builtin_permissions
|
||||
|
||||
def check_user_model(app_configs: None = ..., **kwargs: Any) -> List[CheckMessage]: ...
|
||||
def check_models_permissions(app_configs: None = ..., **kwargs: Any) -> List[Any]: ...
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
from typing import Any, Dict, Optional, Union
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.contrib.auth.models import AnonymousUser, User
|
||||
from django.http.request import HttpRequest
|
||||
from django.utils.functional import SimpleLazyObject
|
||||
|
||||
class PermLookupDict:
|
||||
app_label: django.utils.safestring.SafeText
|
||||
user: SimpleLazyObject
|
||||
def __init__(self, user: SimpleLazyObject, app_label: str) -> None: ...
|
||||
app_label: str
|
||||
user: Any
|
||||
def __init__(self, user: Any, app_label: str) -> None: ...
|
||||
def __getitem__(self, perm_name: str) -> bool: ...
|
||||
def __iter__(self) -> Any: ...
|
||||
def __bool__(self) -> bool: ...
|
||||
|
||||
class PermWrapper:
|
||||
user: SimpleLazyObject = ...
|
||||
def __init__(self, user: Union[AnonymousUser, User]) -> None: ...
|
||||
user: Any = ...
|
||||
def __init__(self, user: Any) -> None: ...
|
||||
def __getitem__(self, app_label: str) -> PermLookupDict: ...
|
||||
def __iter__(self) -> Any: ...
|
||||
def __contains__(self, perm_name: Union[bool, str]) -> bool: ...
|
||||
def __contains__(self, perm_name: Any) -> bool: ...
|
||||
|
||||
def auth(request: HttpRequest) -> Dict[str, Union[PermWrapper, AnonymousUser, User]]: ...
|
||||
def auth(request: HttpRequest) -> Dict[str, Any]: ...
|
||||
|
||||
@@ -1,44 +1,24 @@
|
||||
import collections
|
||||
import datetime
|
||||
from typing import Any, Dict, Iterator, List, Optional, Union, Type
|
||||
from typing import Any, Dict, Iterator, Optional
|
||||
|
||||
from django.contrib.auth.base_user import AbstractBaseUser
|
||||
from django.contrib.auth.models import AbstractUser, User
|
||||
from django.contrib.auth.tokens import PasswordResetTokenGenerator
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.forms.utils import ErrorList
|
||||
from django.http.request import QueryDict
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
|
||||
from django import forms
|
||||
|
||||
UserModel: Any
|
||||
|
||||
class ReadOnlyPasswordHashWidget(forms.Widget):
|
||||
attrs: Dict[Any, Any]
|
||||
template_name: str = ...
|
||||
|
||||
class ReadOnlyPasswordHashField(forms.Field):
|
||||
widget: Any = ...
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def bound_data(self, data: None, initial: str) -> str: ...
|
||||
def has_changed(self, initial: str, data: Optional[str]) -> bool: ...
|
||||
|
||||
class UsernameField(forms.CharField):
|
||||
def to_python(self, value: Optional[str]) -> str: ...
|
||||
class UsernameField(forms.CharField): ...
|
||||
|
||||
class UserCreationForm(forms.ModelForm):
|
||||
auto_id: str
|
||||
data: Dict[str, str]
|
||||
empty_permitted: bool
|
||||
error_class: Type[ErrorList]
|
||||
fields: collections.OrderedDict
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[Any, Any]
|
||||
instance: User
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
error_messages: Any = ...
|
||||
password1: Any = ...
|
||||
password2: Any = ...
|
||||
@@ -46,30 +26,11 @@ class UserCreationForm(forms.ModelForm):
|
||||
def clean_password2(self) -> str: ...
|
||||
|
||||
class UserChangeForm(forms.ModelForm):
|
||||
auto_id: str
|
||||
data: Dict[Any, Any]
|
||||
empty_permitted: bool
|
||||
error_class: Type[ErrorList]
|
||||
fields: collections.OrderedDict
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[str, Optional[Union[List[Any], datetime.datetime, int, str]]]
|
||||
instance: User
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
password: Any = ...
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def clean_password(self) -> str: ...
|
||||
|
||||
class AuthenticationForm(forms.Form):
|
||||
auto_id: str
|
||||
data: QueryDict
|
||||
empty_permitted: bool
|
||||
error_class: Type[ErrorList]
|
||||
fields: collections.OrderedDict
|
||||
files: MultiValueDict
|
||||
initial: Dict[Any, Any]
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
username: Any = ...
|
||||
password: Any = ...
|
||||
error_messages: Any = ...
|
||||
@@ -82,21 +43,12 @@ class AuthenticationForm(forms.Form):
|
||||
def get_invalid_login_error(self) -> ValidationError: ...
|
||||
|
||||
class PasswordResetForm(forms.Form):
|
||||
auto_id: str
|
||||
data: Dict[Any, Any]
|
||||
empty_permitted: bool
|
||||
error_class: Type[ErrorList]
|
||||
fields: collections.OrderedDict
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[Any, Any]
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
email: Any = ...
|
||||
def send_mail(
|
||||
self,
|
||||
subject_template_name: str,
|
||||
email_template_name: str,
|
||||
context: Dict[str, Union[AbstractBaseUser, str]],
|
||||
context: Dict[str, Any],
|
||||
from_email: Optional[str],
|
||||
to_email: str,
|
||||
html_email_template_name: Optional[str] = ...,
|
||||
@@ -116,15 +68,6 @@ class PasswordResetForm(forms.Form):
|
||||
) -> None: ...
|
||||
|
||||
class SetPasswordForm(forms.Form):
|
||||
auto_id: str
|
||||
data: Dict[Any, Any]
|
||||
empty_permitted: bool
|
||||
error_class: Type[ErrorList]
|
||||
fields: collections.OrderedDict
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[Any, Any]
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
error_messages: Any = ...
|
||||
new_password1: Any = ...
|
||||
new_password2: Any = ...
|
||||
@@ -134,31 +77,10 @@ class SetPasswordForm(forms.Form):
|
||||
def save(self, commit: bool = ...) -> AbstractBaseUser: ...
|
||||
|
||||
class PasswordChangeForm(SetPasswordForm):
|
||||
auto_id: str
|
||||
data: Dict[Any, Any]
|
||||
empty_permitted: bool
|
||||
error_class: Type[ErrorList]
|
||||
fields: collections.OrderedDict
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[Any, Any]
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
user: User
|
||||
error_messages: Any = ...
|
||||
old_password: Any = ...
|
||||
field_order: Any = ...
|
||||
def clean_old_password(self) -> str: ...
|
||||
|
||||
class AdminPasswordChangeForm(forms.Form):
|
||||
auto_id: str
|
||||
data: Dict[Any, Any]
|
||||
empty_permitted: bool
|
||||
error_class: Type[ErrorList]
|
||||
fields: collections.OrderedDict
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[Any, Any]
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
error_messages: Any = ...
|
||||
required_css_class: str = ...
|
||||
password1: Any = ...
|
||||
@@ -167,5 +89,3 @@ class AdminPasswordChangeForm(forms.Form):
|
||||
def __init__(self, user: AbstractUser, *args: Any, **kwargs: Any) -> None: ...
|
||||
def clean_password2(self) -> str: ...
|
||||
def save(self, commit: bool = ...) -> AbstractUser: ...
|
||||
@property
|
||||
def changed_data(self) -> List[str]: ...
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
from typing import Any, Dict, Optional, Set, Type, Union
|
||||
from typing import Any, Optional, Set
|
||||
|
||||
from django.contrib.auth.base_user import AbstractBaseUser
|
||||
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm, PasswordResetForm, SetPasswordForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.sites.models import Site
|
||||
from django.contrib.sites.requests import RequestSite
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.http.request import HttpRequest
|
||||
from django.http.response import HttpResponse, HttpResponseRedirect
|
||||
from django.http.response import HttpResponseRedirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import FormView
|
||||
|
||||
@@ -20,29 +15,18 @@ class SuccessURLAllowedHostsMixin:
|
||||
def get_success_url_allowed_hosts(self) -> Set[str]: ...
|
||||
|
||||
class LoginView(SuccessURLAllowedHostsMixin, FormView):
|
||||
form_class: Any = ...
|
||||
authentication_form: Any = ...
|
||||
redirect_field_name: Any = ...
|
||||
template_name: str = ...
|
||||
redirect_authenticated_user: bool = ...
|
||||
extra_context: Any = ...
|
||||
def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
|
||||
def get_success_url(self) -> str: ...
|
||||
def get_redirect_url(self) -> str: ...
|
||||
def get_form_class(self) -> Type[AuthenticationForm]: ...
|
||||
def get_form_kwargs(self) -> Dict[str, Optional[Union[Dict[str, str], HttpRequest, MultiValueDict]]]: ...
|
||||
def form_valid(self, form: AuthenticationForm) -> HttpResponseRedirect: ...
|
||||
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ...
|
||||
|
||||
class LogoutView(SuccessURLAllowedHostsMixin, TemplateView):
|
||||
next_page: Any = ...
|
||||
redirect_field_name: Any = ...
|
||||
template_name: str = ...
|
||||
extra_context: Any = ...
|
||||
def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
|
||||
def post(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> TemplateResponse: ...
|
||||
def get_next_page(self) -> Optional[str]: ...
|
||||
def get_context_data(self, **kwargs: Any): ...
|
||||
|
||||
def logout_then_login(request: HttpRequest, login_url: Optional[str] = ...) -> HttpResponseRedirect: ...
|
||||
def redirect_to_login(
|
||||
@@ -56,55 +40,32 @@ class PasswordContextMixin:
|
||||
class PasswordResetView(PasswordContextMixin, FormView):
|
||||
email_template_name: str = ...
|
||||
extra_email_context: Any = ...
|
||||
form_class: Any = ...
|
||||
from_email: Any = ...
|
||||
html_email_template_name: Any = ...
|
||||
subject_template_name: str = ...
|
||||
success_url: Any = ...
|
||||
template_name: str = ...
|
||||
title: Any = ...
|
||||
token_generator: Any = ...
|
||||
def dispatch(self, *args: Any, **kwargs: Any) -> HttpResponse: ...
|
||||
def form_valid(self, form: PasswordResetForm) -> HttpResponseRedirect: ...
|
||||
|
||||
INTERNAL_RESET_URL_TOKEN: str
|
||||
INTERNAL_RESET_SESSION_TOKEN: str
|
||||
|
||||
class PasswordResetDoneView(PasswordContextMixin, TemplateView):
|
||||
template_name: str = ...
|
||||
title: Any = ...
|
||||
|
||||
class PasswordResetConfirmView(PasswordContextMixin, FormView):
|
||||
form_class: Any = ...
|
||||
post_reset_login: bool = ...
|
||||
post_reset_login_backend: Any = ...
|
||||
success_url: Any = ...
|
||||
template_name: str = ...
|
||||
title: Any = ...
|
||||
token_generator: Any = ...
|
||||
validlink: bool = ...
|
||||
user: Any = ...
|
||||
def dispatch(self, *args: Any, **kwargs: Any) -> HttpResponse: ...
|
||||
def get_user(self, uidb64: str) -> Optional[AbstractBaseUser]: ...
|
||||
def get_form_kwargs(self) -> Dict[str, Optional[Union[Dict[Any, Any], AbstractBaseUser, MultiValueDict]]]: ...
|
||||
def form_valid(self, form: SetPasswordForm) -> HttpResponseRedirect: ...
|
||||
def get_context_data(self, **kwargs: Any): ...
|
||||
|
||||
class PasswordResetCompleteView(PasswordContextMixin, TemplateView):
|
||||
template_name: str = ...
|
||||
title: Any = ...
|
||||
def get_context_data(self, **kwargs: Any): ...
|
||||
|
||||
class PasswordChangeView(PasswordContextMixin, FormView):
|
||||
form_class: Any = ...
|
||||
success_url: Any = ...
|
||||
template_name: str = ...
|
||||
title: Any = ...
|
||||
def dispatch(self, *args: Any, **kwargs: Any) -> HttpResponse: ...
|
||||
def get_form_kwargs(self) -> Dict[str, Optional[Union[Dict[Any, Any], User, MultiValueDict]]]: ...
|
||||
def form_valid(self, form: PasswordChangeForm) -> HttpResponseRedirect: ...
|
||||
|
||||
class PasswordChangeDoneView(PasswordContextMixin, TemplateView):
|
||||
template_name: str = ...
|
||||
title: Any = ...
|
||||
def dispatch(self, *args: Any, **kwargs: Any) -> TemplateResponse: ...
|
||||
|
||||
@@ -1,16 +1,3 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
from .management import create_contenttypes, inject_rename_contenttypes_operations
|
||||
|
||||
class ContentTypesConfig(AppConfig):
|
||||
apps: None
|
||||
label: str
|
||||
models: None
|
||||
models_module: None
|
||||
module: Any
|
||||
path: str
|
||||
name: str = ...
|
||||
verbose_name: Any = ...
|
||||
def ready(self) -> None: ...
|
||||
class ContentTypesConfig(AppConfig): ...
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from django.core.management import BaseCommand
|
||||
from django.core.management.base import CommandParser
|
||||
from django.db.models.deletion import Collector
|
||||
|
||||
from ...management import get_contenttypes_and_models
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
class Command(BaseCommand):
|
||||
stderr: django.core.management.base.OutputWrapper
|
||||
stdout: django.core.management.base.OutputWrapper
|
||||
style: django.core.management.color.Style
|
||||
def add_arguments(self, parser: CommandParser) -> None: ...
|
||||
def handle(self, **options: Any) -> None: ...
|
||||
class Command(BaseCommand): ...
|
||||
|
||||
class NoFastDeleteCollector(Collector):
|
||||
data: collections.OrderedDict
|
||||
data: Dict[str, Any]
|
||||
dependencies: Dict[Any, Any]
|
||||
fast_deletes: List[Any]
|
||||
field_updates: Dict[Any, Any]
|
||||
|
||||
@@ -1,19 +1,7 @@
|
||||
from typing import Any, Dict, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
from django import forms
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
class FlatpageForm(forms.ModelForm):
|
||||
auto_id: str
|
||||
data: Dict[str, Union[List[int], str]]
|
||||
empty_permitted: bool
|
||||
error_class: Type[ErrorList]
|
||||
fields: collections.OrderedDict
|
||||
files: Dict[Any, Any]
|
||||
initial: Dict[str, Union[List[django.contrib.sites.models.Site], int, str]]
|
||||
instance: django.contrib.flatpages.models.FlatPage
|
||||
is_bound: bool
|
||||
label_suffix: str
|
||||
url: Any = ...
|
||||
def clean_url(self) -> str: ...
|
||||
def clean(self) -> Dict[str, Union[bool, QuerySet, str]]: ...
|
||||
|
||||
@@ -9,5 +9,5 @@ class FlatPage(models.Model):
|
||||
enable_comments: models.BooleanField = ...
|
||||
template_name: models.CharField = ...
|
||||
registration_required: models.BooleanField = ...
|
||||
sites: models.ManyToManyField[Site] = ...
|
||||
sites: models.ManyToManyField[Site, Site] = ...
|
||||
def get_absolute_url(self) -> str: ...
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
from typing import Optional
|
||||
|
||||
from django.contrib.sitemaps import Sitemap
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
class FlatPageSitemap(Sitemap):
|
||||
def items(self) -> QuerySet: ...
|
||||
class FlatPageSitemap(Sitemap): ...
|
||||
|
||||
11
django-stubs/contrib/messages/constants.pyi
Normal file
11
django-stubs/contrib/messages/constants.pyi
Normal file
@@ -0,0 +1,11 @@
|
||||
from typing import Dict
|
||||
|
||||
DEBUG: int = ...
|
||||
INFO: int = ...
|
||||
SUCCESS: int = ...
|
||||
WARNING: int = ...
|
||||
ERROR: int = ...
|
||||
|
||||
DEFAULT_TAGS: Dict[int, str] = ...
|
||||
|
||||
DEFAULT_LEVELS: Dict[str, int] = ...
|
||||
@@ -16,7 +16,7 @@ class Message:
|
||||
def level_tag(self) -> str: ...
|
||||
|
||||
class BaseStorage:
|
||||
request: Any = ...
|
||||
request: HttpRequest = ...
|
||||
used: bool = ...
|
||||
added_new: bool = ...
|
||||
def __init__(self, request: HttpRequest, *args: Any, **kwargs: Any) -> None: ...
|
||||
|
||||
@@ -1,49 +1,20 @@
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
from typing import Any
|
||||
|
||||
from django.contrib.messages.storage.base import BaseStorage, Message
|
||||
from django.contrib.messages.storage.base import BaseStorage
|
||||
|
||||
class MessageEncoder(json.JSONEncoder):
|
||||
allow_nan: bool
|
||||
check_circular: bool
|
||||
ensure_ascii: bool
|
||||
indent: None
|
||||
item_separator: str
|
||||
key_separator: str
|
||||
skipkeys: bool
|
||||
sort_keys: bool
|
||||
message_key: str = ...
|
||||
def default(self, obj: Message) -> List[Union[int, str]]: ...
|
||||
|
||||
class MessageDecoder(json.JSONDecoder):
|
||||
def process_messages(
|
||||
self,
|
||||
obj: Union[
|
||||
Dict[
|
||||
str, Union[List[Union[Dict[str, List[Union[int, str]]], List[Union[int, str]]]], List[Union[int, str]]]
|
||||
],
|
||||
List[Union[List[Union[int, str]], str]],
|
||||
str,
|
||||
],
|
||||
) -> Union[
|
||||
Dict[str, Union[List[Union[Dict[str, Message], Message]], Message]],
|
||||
List[Union[Dict[str, Union[List[Union[Dict[str, Message], Message]], Message]], Message]],
|
||||
List[Union[Message, str]],
|
||||
Message,
|
||||
str,
|
||||
]: ...
|
||||
def decode(
|
||||
self, s: str, **kwargs: Any
|
||||
) -> Union[
|
||||
List[Union[Dict[str, Union[List[Union[Dict[str, Message], Message]], Message]], Message]],
|
||||
List[Union[Message, str]],
|
||||
Message,
|
||||
]: ...
|
||||
def process_messages(self, obj: Any) -> Any: ...
|
||||
|
||||
class CookieStorage(BaseStorage):
|
||||
added_new: bool
|
||||
request: WSGIRequest
|
||||
used: bool
|
||||
cookie_name: str = ...
|
||||
max_cookie_size: int = ...
|
||||
not_finished: str = ...
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from django.contrib.messages.storage.base import BaseStorage
|
||||
|
||||
class FallbackStorage(BaseStorage):
|
||||
added_new: bool
|
||||
request: WSGIRequest
|
||||
used: bool
|
||||
storage_classes: Any = ...
|
||||
storages: Any = ...
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
from typing import Any, List, Optional, Union
|
||||
from typing import Any, List, Optional, Sequence, Union
|
||||
|
||||
from django.contrib.messages.storage.base import BaseStorage, Message
|
||||
from django.contrib.messages.storage.base import BaseStorage
|
||||
from django.http.request import HttpRequest
|
||||
|
||||
class SessionStorage(BaseStorage):
|
||||
added_new: bool
|
||||
request: WSGIRequest
|
||||
used: bool
|
||||
session_key: str = ...
|
||||
def __init__(self, request: HttpRequest, *args: Any, **kwargs: Any) -> None: ...
|
||||
def serialize_messages(self, messages: Union[List[Message], List[str]]) -> str: ...
|
||||
def deserialize_messages(
|
||||
self, data: Optional[Union[List[Any], str]]
|
||||
) -> Optional[Union[List[Message], List[str]]]: ...
|
||||
def serialize_messages(self, messages: Sequence[Any]) -> str: ...
|
||||
def deserialize_messages(self, data: Optional[Union[List[Any], str]]) -> Optional[List[Any]]: ...
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, Optional, Union
|
||||
|
||||
from django.db.models.base import Model
|
||||
|
||||
VALID_KEY_CHARS: Any
|
||||
|
||||
class CreateError(Exception): ...
|
||||
@@ -18,8 +16,8 @@ class SessionBase(Dict[str, Any]):
|
||||
def set_test_cookie(self) -> None: ...
|
||||
def test_cookie_worked(self) -> bool: ...
|
||||
def delete_test_cookie(self) -> None: ...
|
||||
def encode(self, session_dict: Dict[str, Model]) -> str: ...
|
||||
def decode(self, session_data: Union[bytes, str]) -> Dict[str, Model]: ...
|
||||
def encode(self, session_dict: Dict[str, Any]) -> str: ...
|
||||
def decode(self, session_data: Union[bytes, str]) -> Dict[str, Any]: ...
|
||||
def has_key(self, key: Any): ...
|
||||
def keys(self): ...
|
||||
def values(self): ...
|
||||
@@ -33,7 +31,7 @@ class SessionBase(Dict[str, Any]):
|
||||
def get_expire_at_browser_close(self) -> bool: ...
|
||||
def flush(self) -> None: ...
|
||||
def cycle_key(self) -> None: ...
|
||||
def exists(self, session_key: str) -> None: ...
|
||||
def exists(self, session_key: str) -> bool: ...
|
||||
def create(self) -> None: ...
|
||||
def save(self, must_create: bool = ...) -> None: ...
|
||||
def delete(self, session_key: Optional[Any] = ...) -> None: ...
|
||||
|
||||
@@ -1,23 +1,11 @@
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.contrib.sessions.backends.base import SessionBase
|
||||
|
||||
from django.contrib.sessions.serializers import JSONSerializer
|
||||
|
||||
KEY_PREFIX: str
|
||||
|
||||
class SessionStore(SessionBase):
|
||||
accessed: bool
|
||||
serializer: JSONSerializer
|
||||
cache_key_prefix: Any = ...
|
||||
def __init__(self, session_key: Optional[str] = ...) -> None: ...
|
||||
@property
|
||||
def cache_key(self) -> str: ...
|
||||
def load(self) -> Dict[str, str]: ...
|
||||
modified: bool = ...
|
||||
def create(self) -> None: ...
|
||||
def save(self, must_create: bool = ...) -> None: ...
|
||||
def exists(self, session_key: Optional[str]) -> bool: ...
|
||||
def delete(self, session_key: Optional[str] = ...) -> None: ...
|
||||
@classmethod
|
||||
def clear_expired(cls) -> None: ...
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.contrib.sessions.backends.db import SessionStore as DBStore
|
||||
|
||||
KEY_PREFIX: str
|
||||
|
||||
class SessionStore(DBStore):
|
||||
accessed: bool
|
||||
modified: bool
|
||||
serializer: Type[django.core.signing.JSONSerializer]
|
||||
cache_key_prefix: Any = ...
|
||||
def __init__(self, session_key: Optional[str] = ...) -> None: ...
|
||||
@property
|
||||
def cache_key(self) -> str: ...
|
||||
def load(self) -> Dict[str, str]: ...
|
||||
def exists(self, session_key: Optional[str]) -> bool: ...
|
||||
def save(self, must_create: bool = ...) -> None: ...
|
||||
def delete(self, session_key: Optional[str] = ...) -> None: ...
|
||||
def flush(self) -> None: ...
|
||||
|
||||
@@ -1,24 +1,13 @@
|
||||
from typing import Dict, Optional, Type, Union
|
||||
from typing import Dict, Optional, Type
|
||||
|
||||
from django.contrib.sessions.backends.base import SessionBase
|
||||
from django.contrib.sessions.base_session import AbstractBaseSession
|
||||
from django.contrib.sessions.models import Session
|
||||
from django.core.signing import Serializer
|
||||
from django.db.models.base import Model
|
||||
|
||||
class SessionStore(SessionBase):
|
||||
accessed: bool
|
||||
serializer: Type[Serializer]
|
||||
def __init__(self, session_key: Optional[str] = ...) -> None: ...
|
||||
@classmethod
|
||||
def get_model_class(cls) -> Type[Session]: ...
|
||||
def model(self) -> Type[AbstractBaseSession]: ...
|
||||
def load(self) -> Dict[str, Union[Model, int, str]]: ...
|
||||
def exists(self, session_key: Optional[str]) -> bool: ...
|
||||
modified: bool = ...
|
||||
def create(self) -> None: ...
|
||||
def create_model_instance(self, data: Dict[str, Model]) -> AbstractBaseSession: ...
|
||||
def save(self, must_create: bool = ...) -> None: ...
|
||||
def delete(self, session_key: Optional[str] = ...) -> None: ...
|
||||
@classmethod
|
||||
def clear_expired(cls) -> None: ...
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
from typing import Any, Dict, Optional, Union
|
||||
from typing import Optional
|
||||
|
||||
from django.contrib.sessions.backends.base import SessionBase
|
||||
|
||||
class SessionStore(SessionBase):
|
||||
accessed: bool
|
||||
serializer: Type[django.core.signing.JSONSerializer]
|
||||
storage_path: str = ...
|
||||
file_prefix: str = ...
|
||||
def __init__(self, session_key: Optional[str] = ...) -> None: ...
|
||||
def load(self) -> Dict[str, Union[int, str]]: ...
|
||||
modified: bool = ...
|
||||
def create(self) -> None: ...
|
||||
def save(self, must_create: bool = ...) -> None: ...
|
||||
def exists(self, session_key: Optional[str]) -> bool: ...
|
||||
def delete(self, session_key: Optional[str] = ...) -> None: ...
|
||||
def clean(self) -> None: ...
|
||||
@classmethod
|
||||
def clear_expired(cls) -> None: ...
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, Optional, Union
|
||||
|
||||
from django.contrib.sessions.backends.base import SessionBase
|
||||
|
||||
class SessionStore(SessionBase):
|
||||
accessed: bool
|
||||
serializer: Type[django.core.signing.JSONSerializer]
|
||||
def load(self) -> Dict[str, Union[datetime, str]]: ...
|
||||
modified: bool = ...
|
||||
def create(self) -> None: ...
|
||||
def save(self, must_create: bool = ...) -> None: ...
|
||||
def exists(self, session_key: Optional[str] = ...) -> bool: ...
|
||||
def delete(self, session_key: Optional[str] = ...) -> None: ...
|
||||
def cycle_key(self) -> None: ...
|
||||
@classmethod
|
||||
def clear_expired(cls) -> None: ...
|
||||
class SessionStore(SessionBase): ...
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
class Command(BaseCommand):
|
||||
stderr: django.core.management.base.OutputWrapper
|
||||
stdout: django.core.management.base.OutputWrapper
|
||||
style: django.core.management.color.Style
|
||||
help: str = ...
|
||||
def handle(self, **options: Any) -> None: ...
|
||||
class Command(BaseCommand): ...
|
||||
|
||||
@@ -15,7 +15,7 @@ def ping_google(sitemap_url: Optional[str] = ..., ping_url: str = ...) -> None:
|
||||
|
||||
class Sitemap:
|
||||
limit: int = ...
|
||||
protocol: Any = ...
|
||||
protocol: Optional[str] = ...
|
||||
def items(self) -> List[Any]: ...
|
||||
def location(self, obj: Model) -> str: ...
|
||||
@property
|
||||
@@ -29,7 +29,6 @@ class GenericSitemap(Sitemap):
|
||||
changefreq: Optional[str] = ...
|
||||
queryset: QuerySet = ...
|
||||
date_field: None = ...
|
||||
protocol: Optional[str] = ...
|
||||
def __init__(
|
||||
self,
|
||||
info_dict: Dict[str, Union[datetime, QuerySet, str]],
|
||||
@@ -37,7 +36,6 @@ class GenericSitemap(Sitemap):
|
||||
changefreq: Optional[str] = ...,
|
||||
protocol: Optional[str] = ...,
|
||||
) -> None: ...
|
||||
def items(self) -> QuerySet: ...
|
||||
def lastmod(self, item: Model) -> Optional[datetime]: ...
|
||||
|
||||
default_app_config: str
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
from typing import Any
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
class SitesConfig(AppConfig):
|
||||
apps: None
|
||||
label: str
|
||||
models: None
|
||||
models_module: None
|
||||
module: Any
|
||||
path: str
|
||||
name: str = ...
|
||||
verbose_name: Any = ...
|
||||
def ready(self) -> None: ...
|
||||
class SitesConfig(AppConfig): ...
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
class StaticFilesConfig(AppConfig):
|
||||
apps: None
|
||||
label: str
|
||||
models: None
|
||||
models_module: None
|
||||
module: Any
|
||||
path: str
|
||||
name: str = ...
|
||||
verbose_name: Any = ...
|
||||
ignore_patterns: Any = ...
|
||||
def ready(self) -> None: ...
|
||||
|
||||
@@ -1,25 +1,21 @@
|
||||
from typing import Any, Iterator, List, Optional, Tuple, Union, Mapping, overload
|
||||
from typing import Any, Iterable, Iterator, List, Mapping, Optional, Union, overload
|
||||
|
||||
from django.contrib.staticfiles.storage import StaticFilesStorage
|
||||
from django.core.checks.messages import Error
|
||||
from django.core.files.storage import DefaultStorage, FileSystemStorage, Storage
|
||||
from django.core.files.storage import Storage
|
||||
from typing_extensions import Literal
|
||||
|
||||
searched_locations: Any
|
||||
|
||||
class BaseFinder:
|
||||
def check(self, **kwargs: Any) -> Any: ...
|
||||
def find(self, path: Any, all: bool = ...) -> None: ...
|
||||
def list(self, ignore_patterns: Any) -> None: ...
|
||||
def check(self, **kwargs: Any) -> List[Error]: ...
|
||||
def find(self, path: str, all: bool = ...) -> Optional[Any]: ...
|
||||
def list(self, ignore_patterns: Any) -> Iterable[Any]: ...
|
||||
|
||||
class FileSystemFinder(BaseFinder):
|
||||
locations: List[Any] = ...
|
||||
storages: Mapping[str, Any] = ...
|
||||
def __init__(self, app_names: None = ..., *args: Any, **kwargs: Any) -> None: ...
|
||||
def check(self, **kwargs: Any) -> List[Error]: ...
|
||||
def find(self, path: str, all: bool = ...) -> Union[List[str], str]: ...
|
||||
def find_location(self, root: str, path: str, prefix: str = ...) -> Optional[str]: ...
|
||||
def list(self, ignore_patterns: List[str]) -> Iterator[Tuple[str, FileSystemStorage]]: ...
|
||||
|
||||
class AppDirectoriesFinder(BaseFinder):
|
||||
storage_class: Any = ...
|
||||
@@ -27,15 +23,11 @@ class AppDirectoriesFinder(BaseFinder):
|
||||
apps: List[str] = ...
|
||||
storages: Mapping[str, Any] = ...
|
||||
def __init__(self, app_names: None = ..., *args: Any, **kwargs: Any) -> None: ...
|
||||
def list(self, ignore_patterns: List[str]) -> Iterator[Tuple[str, FileSystemStorage]]: ...
|
||||
def find(self, path: str, all: bool = ...) -> Union[List[str], str]: ...
|
||||
def find_in_app(self, app: str, path: str) -> Optional[str]: ...
|
||||
|
||||
class BaseStorageFinder(BaseFinder):
|
||||
storage: Storage = ...
|
||||
def __init__(self, storage: Optional[Storage] = ..., *args: Any, **kwargs: Any) -> None: ...
|
||||
def find(self, path: str, all: bool = ...) -> Union[List[str], str]: ...
|
||||
def list(self, ignore_patterns: List[str]) -> Iterator[Tuple[str, DefaultStorage]]: ...
|
||||
|
||||
class DefaultStorageFinder(BaseStorageFinder): ...
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from django.core.handlers.wsgi import WSGIHandler, WSGIRequest
|
||||
|
||||
@@ -7,9 +7,6 @@ class StaticFilesHandler(WSGIHandler):
|
||||
application: WSGIHandler = ...
|
||||
base_url: Any = ...
|
||||
def __init__(self, application: WSGIHandler) -> None: ...
|
||||
def load_middleware(self) -> None: ...
|
||||
def get_base_url(self) -> str: ...
|
||||
def file_path(self, url: str) -> str: ...
|
||||
def serve(self, request: WSGIRequest) -> Any: ...
|
||||
def get_response(self, request: WSGIRequest) -> Any: ...
|
||||
def __call__(self, environ: Any, start_response: Any): ...
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
class Command(BaseCommand):
|
||||
stderr: django.core.management.base.OutputWrapper
|
||||
stdout: django.core.management.base.OutputWrapper
|
||||
help: str = ...
|
||||
requires_system_checks: bool = ...
|
||||
copied_files: Any = ...
|
||||
symlinked_files: Any = ...
|
||||
unmodified_files: Any = ...
|
||||
post_processed_files: Any = ...
|
||||
storage: Any = ...
|
||||
style: django.core.management.color.Style = ...
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def local(self) -> bool: ...
|
||||
def add_arguments(self, parser: CommandParser) -> None: ...
|
||||
interactive: Any = ...
|
||||
verbosity: Any = ...
|
||||
symlink: Any = ...
|
||||
@@ -26,7 +20,6 @@ class Command(BaseCommand):
|
||||
post_process: Any = ...
|
||||
def set_options(self, **options: Any) -> None: ...
|
||||
def collect(self) -> Dict[str, List[str]]: ...
|
||||
def handle(self, **options: Any) -> Optional[str]: ...
|
||||
def log(self, msg: str, level: int = ...) -> None: ...
|
||||
def is_local_storage(self) -> bool: ...
|
||||
def clear_dir(self, path: str) -> None: ...
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
from typing import Any, Optional
|
||||
from django.core.management.base import LabelCommand
|
||||
|
||||
from django.core.management.base import CommandParser, LabelCommand
|
||||
|
||||
class Command(LabelCommand):
|
||||
stderr: django.core.management.base.OutputWrapper
|
||||
stdout: django.core.management.base.OutputWrapper
|
||||
style: django.core.management.color.Style
|
||||
help: str = ...
|
||||
label: str = ...
|
||||
def add_arguments(self, parser: CommandParser) -> None: ...
|
||||
def handle_label(self, path: str, **options: Any) -> str: ...
|
||||
class Command(LabelCommand): ...
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
from typing import Any, Optional
|
||||
from django.core.management.commands.runserver import Command as RunserverCommand # type: ignore
|
||||
|
||||
from django.contrib.staticfiles.handlers import StaticFilesHandler
|
||||
from django.core.management.base import CommandParser
|
||||
from django.core.management.commands.runserver import Command as RunserverCommand
|
||||
|
||||
class Command(RunserverCommand):
|
||||
stderr: django.core.management.base.OutputWrapper
|
||||
stdout: django.core.management.base.OutputWrapper
|
||||
style: django.core.management.color.Style
|
||||
help: str = ...
|
||||
def add_arguments(self, parser: CommandParser) -> None: ...
|
||||
def get_handler(self, *args: Any, **options: Any) -> StaticFilesHandler: ...
|
||||
class Command(RunserverCommand): ...
|
||||
|
||||
@@ -20,7 +20,6 @@ class HashedFilesMixin:
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def file_hash(self, name: str, content: File = ...) -> str: ...
|
||||
def hashed_name(self, name: str, content: Optional[File] = ..., filename: Optional[str] = ...) -> str: ...
|
||||
def url(self, name: SafeText, force: bool = ...) -> str: ...
|
||||
def url_converter(self, name: str, hashed_files: OrderedDict, template: str = ...) -> Callable: ...
|
||||
def post_process(
|
||||
self, paths: OrderedDict, dry_run: bool = ..., **options: Any
|
||||
@@ -33,16 +32,13 @@ class ManifestFilesMixin(HashedFilesMixin):
|
||||
manifest_version: str = ...
|
||||
manifest_name: str = ...
|
||||
manifest_strict: bool = ...
|
||||
hashed_files: Any = ...
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def read_manifest(self) -> Any: ...
|
||||
def load_manifest(self) -> OrderedDict: ...
|
||||
def post_process(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def save_manifest(self) -> None: ...
|
||||
def stored_name(self, name: str) -> str: ...
|
||||
|
||||
class _MappingCache:
|
||||
cache: django.core.cache.DefaultCacheProxy = ...
|
||||
cache: Any = ...
|
||||
def __init__(self, cache: Any) -> None: ...
|
||||
def __setitem__(self, key: Any, value: Any) -> None: ...
|
||||
def __getitem__(self, key: Any): ...
|
||||
@@ -51,9 +47,7 @@ class _MappingCache:
|
||||
def get(self, key: Any, default: Optional[Any] = ...): ...
|
||||
|
||||
class CachedFilesMixin(HashedFilesMixin):
|
||||
hashed_files: Any = ...
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def hash_key(self, name: str) -> str: ...
|
||||
|
||||
class CachedStaticFilesStorage(CachedFilesMixin, StaticFilesStorage): ...
|
||||
class ManifestStaticFilesStorage(ManifestFilesMixin, StaticFilesStorage): ...
|
||||
|
||||
22
django-stubs/core/cache/backends/base.pyi
vendored
22
django-stubs/core/cache/backends/base.pyi
vendored
@@ -1,5 +1,4 @@
|
||||
from collections import OrderedDict
|
||||
from typing import Any, Callable, Dict, List, Optional, Union
|
||||
from typing import Any, Callable, Dict, Iterable, List, Optional, Union
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
@@ -9,7 +8,7 @@ class CacheKeyWarning(RuntimeWarning): ...
|
||||
DEFAULT_TIMEOUT: Any
|
||||
MEMCACHE_MAX_KEY_LENGTH: int
|
||||
|
||||
def default_key_func(key: Union[int, str], key_prefix: str, version: Union[int, str]) -> str: ...
|
||||
def default_key_func(key: Any, key_prefix: str, version: Any) -> str: ...
|
||||
def get_key_func(key_func: Optional[Union[Callable, str]]) -> Callable: ...
|
||||
|
||||
class BaseCache:
|
||||
@@ -17,9 +16,9 @@ class BaseCache:
|
||||
key_prefix: str = ...
|
||||
version: int = ...
|
||||
key_func: Callable = ...
|
||||
def __init__(self, params: Dict[str, Optional[Union[Callable, Dict[str, int], int, str]]]) -> None: ...
|
||||
def __init__(self, params: Dict[str, Any]) -> None: ...
|
||||
def get_backend_timeout(self, timeout: Any = ...) -> Optional[float]: ...
|
||||
def make_key(self, key: Union[int, str], version: Optional[Union[int, str]] = ...) -> str: ...
|
||||
def make_key(self, key: Any, version: Optional[Any] = ...) -> str: ...
|
||||
def add(self, key: Any, value: Any, timeout: Any = ..., version: Optional[Any] = ...) -> None: ...
|
||||
def get(self, key: Any, default: Optional[Any] = ..., version: Optional[Any] = ...) -> Any: ...
|
||||
def set(self, key: Any, value: Any, timeout: Any = ..., version: Optional[Any] = ...) -> None: ...
|
||||
@@ -27,19 +26,14 @@ class BaseCache:
|
||||
def delete(self, key: Any, version: Optional[Any] = ...) -> None: ...
|
||||
def get_many(self, keys: List[str], version: Optional[int] = ...) -> Dict[str, Union[int, str]]: ...
|
||||
def get_or_set(
|
||||
self, key: str, default: Optional[Union[Callable, int, str]], timeout: Any = ..., version: Optional[int] = ...
|
||||
) -> Optional[Union[int, str]]: ...
|
||||
self, key: Any, default: Optional[Any], timeout: Any = ..., version: Optional[int] = ...
|
||||
) -> Optional[Any]: ...
|
||||
def has_key(self, key: Any, version: Optional[Any] = ...): ...
|
||||
def incr(self, key: str, delta: int = ..., version: Optional[int] = ...) -> int: ...
|
||||
def decr(self, key: str, delta: int = ..., version: Optional[int] = ...) -> int: ...
|
||||
def __contains__(self, key: str) -> bool: ...
|
||||
def set_many(
|
||||
self,
|
||||
data: Union[Dict[str, bytes], Dict[str, int], Dict[str, str], OrderedDict],
|
||||
timeout: Any = ...,
|
||||
version: Optional[Union[int, str]] = ...,
|
||||
) -> List[Any]: ...
|
||||
def delete_many(self, keys: Union[Dict[str, str], List[str]], version: None = ...) -> None: ...
|
||||
def set_many(self, data: Dict[str, Any], timeout: Any = ..., version: Optional[Any] = ...) -> List[Any]: ...
|
||||
def delete_many(self, keys: Iterable[Any], version: Optional[Any] = ...) -> None: ...
|
||||
def clear(self) -> None: ...
|
||||
def validate_key(self, key: str) -> None: ...
|
||||
def incr_version(self, key: str, delta: int = ..., version: Optional[int] = ...) -> int: ...
|
||||
|
||||
23
django-stubs/core/cache/backends/db.pyi
vendored
23
django-stubs/core/cache/backends/db.pyi
vendored
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Callable, Dict, Optional, Union
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.core.cache.backends.base import BaseCache
|
||||
|
||||
@@ -16,24 +16,7 @@ class Options:
|
||||
def __init__(self, table: str) -> None: ...
|
||||
|
||||
class BaseDatabaseCache(BaseCache):
|
||||
default_timeout: int
|
||||
key_func: Callable
|
||||
key_prefix: str
|
||||
version: int
|
||||
cache_model_class: Any = ...
|
||||
def __init__(self, table: str, params: Dict[str, Union[Callable, Dict[str, int], int, str]]) -> None: ...
|
||||
def __init__(self, table: str, params: Dict[str, Any]) -> None: ...
|
||||
|
||||
class DatabaseCache(BaseDatabaseCache):
|
||||
default_timeout: int
|
||||
key_func: Callable
|
||||
key_prefix: str
|
||||
version: int
|
||||
def get(self, key: str, default: Optional[Union[int, str]] = ..., version: Optional[int] = ...) -> Any: ...
|
||||
def set(self, key: str, value: Any, timeout: Any = ..., version: Optional[int] = ...) -> None: ...
|
||||
def add(
|
||||
self, key: str, value: Union[Dict[str, int], bytes, int, str], timeout: Any = ..., version: Optional[int] = ...
|
||||
) -> bool: ...
|
||||
def touch(self, key: str, timeout: Any = ..., version: None = ...) -> bool: ...
|
||||
def delete(self, key: str, version: Optional[int] = ...) -> None: ...
|
||||
def has_key(self, key: str, version: Optional[int] = ...) -> Any: ...
|
||||
def clear(self) -> None: ...
|
||||
class DatabaseCache(BaseDatabaseCache): ...
|
||||
|
||||
15
django-stubs/core/cache/backends/dummy.pyi
vendored
15
django-stubs/core/cache/backends/dummy.pyi
vendored
@@ -1,19 +1,6 @@
|
||||
from typing import Any, Dict, Optional, Union, Callable
|
||||
from typing import Any
|
||||
|
||||
from django.core.cache.backends.base import BaseCache
|
||||
|
||||
class DummyCache(BaseCache):
|
||||
default_timeout: int
|
||||
key_func: Callable
|
||||
key_prefix: str
|
||||
version: int
|
||||
def __init__(self, host: str, *args: Any, **kwargs: Any) -> None: ...
|
||||
def add(self, key: str, value: str, timeout: Any = ..., version: None = ...) -> bool: ...
|
||||
def get(self, key: str, default: Optional[str] = ..., version: Optional[int] = ...) -> Optional[str]: ...
|
||||
def set(
|
||||
self, key: str, value: Union[Dict[str, Any], int, str], timeout: Any = ..., version: Optional[str] = ...
|
||||
) -> None: ...
|
||||
def touch(self, key: str, timeout: Any = ..., version: None = ...) -> bool: ...
|
||||
def delete(self, key: str, version: None = ...) -> None: ...
|
||||
def has_key(self, key: str, version: None = ...) -> bool: ...
|
||||
def clear(self) -> None: ...
|
||||
|
||||
19
django-stubs/core/cache/backends/filebased.pyi
vendored
19
django-stubs/core/cache/backends/filebased.pyi
vendored
@@ -1,22 +1,7 @@
|
||||
from typing import Any, Callable, Dict, Optional, Union
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.core.cache.backends.base import BaseCache
|
||||
|
||||
class FileBasedCache(BaseCache):
|
||||
default_timeout: int
|
||||
key_func: Callable
|
||||
key_prefix: str
|
||||
version: int
|
||||
cache_suffix: str = ...
|
||||
def __init__(self, dir: str, params: Dict[str, Union[Callable, Dict[str, int], int, str]]) -> None: ...
|
||||
def add(
|
||||
self, key: str, value: Union[Dict[str, int], bytes, int, str], timeout: Any = ..., version: Optional[int] = ...
|
||||
) -> bool: ...
|
||||
def get(
|
||||
self, key: str, default: Optional[Union[int, str]] = ..., version: Optional[int] = ...
|
||||
) -> Optional[str]: ...
|
||||
def set(self, key: str, value: Any, timeout: Any = ..., version: Optional[int] = ...) -> None: ...
|
||||
def touch(self, key: str, timeout: Any = ..., version: None = ...) -> bool: ...
|
||||
def delete(self, key: str, version: Optional[int] = ...) -> None: ...
|
||||
def has_key(self, key: str, version: Optional[int] = ...) -> bool: ...
|
||||
def clear(self) -> None: ...
|
||||
def __init__(self, dir: str, params: Dict[str, Any]) -> None: ...
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
from ctypes import Structure, c_int64, c_ulong, c_void_p
|
||||
from io import BufferedRandom, TextIOWrapper
|
||||
from typing import Union
|
||||
from ctypes import Structure, Union
|
||||
from typing import Any
|
||||
|
||||
LOCK_SH: int
|
||||
LOCK_NB: int
|
||||
LOCK_EX: int
|
||||
ULONG_PTR = c_int64
|
||||
ULONG_PTR = c_ulong
|
||||
PVOID = c_void_p
|
||||
ULONG_PTR: Any = ...
|
||||
PVOID: Any = ...
|
||||
|
||||
class _OFFSET(Structure): ...
|
||||
class _OFFSET_UNION(Union): ...
|
||||
class OVERLAPPED(Structure): ...
|
||||
|
||||
def lock(f: Union[BufferedRandom, TextIOWrapper, int], flags: int) -> bool: ...
|
||||
def unlock(f: Union[BufferedRandom, int]) -> bool: ...
|
||||
def lock(f: Any, flags: int) -> bool: ...
|
||||
def unlock(f: Any) -> bool: ...
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from typing import Any, List, Optional, Tuple
|
||||
|
||||
from .backends.base import BaseEmailBackend
|
||||
from .message import (
|
||||
BadHeaderError as BadHeaderError,
|
||||
DEFAULT_ATTACHMENT_MIME_TYPE as DEFAULT_ATTACHMENT_MIME_TYPE,
|
||||
@@ -12,7 +11,7 @@ from .message import (
|
||||
)
|
||||
from .utils import CachedDnsName as CachedDnsName, DNS_NAME as DNS_NAME
|
||||
|
||||
def get_connection(backend: Optional[str] = ..., fail_silently: bool = ..., **kwds: Any) -> BaseEmailBackend: ...
|
||||
def get_connection(backend: Optional[str] = ..., fail_silently: bool = ..., **kwds: Any) -> Any: ...
|
||||
def send_mail(
|
||||
subject: str,
|
||||
message: str,
|
||||
@@ -21,7 +20,7 @@ def send_mail(
|
||||
fail_silently: bool = ...,
|
||||
auth_user: Optional[str] = ...,
|
||||
auth_password: Optional[str] = ...,
|
||||
connection: Optional[BaseEmailBackend] = ...,
|
||||
connection: Optional[Any] = ...,
|
||||
html_message: Optional[str] = ...,
|
||||
) -> int: ...
|
||||
def send_mass_mail(
|
||||
@@ -29,20 +28,20 @@ def send_mass_mail(
|
||||
fail_silently: bool = ...,
|
||||
auth_user: Optional[str] = ...,
|
||||
auth_password: Optional[str] = ...,
|
||||
connection: Optional[BaseEmailBackend] = ...,
|
||||
connection: Optional[Any] = ...,
|
||||
) -> int: ...
|
||||
def mail_admins(
|
||||
subject: str,
|
||||
message: str,
|
||||
fail_silently: bool = ...,
|
||||
connection: Optional[BaseEmailBackend] = ...,
|
||||
connection: Optional[Any] = ...,
|
||||
html_message: Optional[str] = ...,
|
||||
) -> None: ...
|
||||
def mail_managers(
|
||||
subject: str,
|
||||
message: str,
|
||||
fail_silently: bool = ...,
|
||||
connection: Optional[BaseEmailBackend] = ...,
|
||||
connection: Optional[Any] = ...,
|
||||
html_message: Optional[str] = ...,
|
||||
) -> None: ...
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
from email._policybase import Policy
|
||||
from email._policybase import Policy # type: ignore
|
||||
from email.mime.message import MIMEMessage
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union, Sequence
|
||||
|
||||
from django.core.mail.backends.base import BaseEmailBackend
|
||||
from django.utils.safestring import SafeText
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
|
||||
|
||||
utf8_charset: Any
|
||||
utf8_charset_qp: Any
|
||||
@@ -20,16 +17,13 @@ def forbid_multi_line_headers(name: str, val: str, encoding: str) -> Tuple[str,
|
||||
def split_addr(addr: str, encoding: str) -> Tuple[str, str]: ...
|
||||
def sanitize_address(addr: Union[Tuple[str, str], str], encoding: str) -> str: ...
|
||||
|
||||
class MIMEMixin:
|
||||
def as_string(self, unixfrom: bool = ..., linesep: str = ...) -> str: ...
|
||||
def as_bytes(self, unixfrom: bool = ..., linesep: str = ...) -> bytes: ...
|
||||
class MIMEMixin: ...
|
||||
|
||||
class SafeMIMEMessage(MIMEMixin, MIMEMessage):
|
||||
defects: List[Any]
|
||||
epilogue: None
|
||||
policy: Policy
|
||||
preamble: None
|
||||
def __setitem__(self, name: str, val: str) -> None: ...
|
||||
|
||||
class SafeMIMEText(MIMEMixin, MIMEText):
|
||||
defects: List[Any]
|
||||
@@ -38,8 +32,6 @@ class SafeMIMEText(MIMEMixin, MIMEText):
|
||||
preamble: None
|
||||
encoding: str = ...
|
||||
def __init__(self, _text: str, _subtype: str = ..., _charset: str = ...) -> None: ...
|
||||
def __setitem__(self, name: str, val: str) -> None: ...
|
||||
def set_payload(self, payload: str, charset: str = ...) -> None: ...
|
||||
|
||||
class SafeMIMEMultipart(MIMEMixin, MIMEMultipart):
|
||||
defects: List[Any]
|
||||
@@ -50,7 +42,6 @@ class SafeMIMEMultipart(MIMEMixin, MIMEMultipart):
|
||||
def __init__(
|
||||
self, _subtype: str = ..., boundary: None = ..., _subparts: None = ..., encoding: str = ..., **_params: Any
|
||||
) -> None: ...
|
||||
def __setitem__(self, name: str, val: str) -> None: ...
|
||||
|
||||
class EmailMessage:
|
||||
content_subtype: str = ...
|
||||
@@ -65,7 +56,7 @@ class EmailMessage:
|
||||
body: str = ...
|
||||
attachments: List[Any] = ...
|
||||
extra_headers: Dict[Any, Any] = ...
|
||||
connection: None = ...
|
||||
connection: Any = ...
|
||||
def __init__(
|
||||
self,
|
||||
subject: str = ...,
|
||||
@@ -73,13 +64,13 @@ class EmailMessage:
|
||||
from_email: Optional[str] = ...,
|
||||
to: Optional[Union[Sequence[str], str]] = ...,
|
||||
bcc: Optional[Union[Sequence[str], str]] = ...,
|
||||
connection: Optional[BaseEmailBackend] = ...,
|
||||
connection: Optional[Any] = ...,
|
||||
attachments: Optional[Union[List[Tuple[str, str]], List[MIMEText]]] = ...,
|
||||
headers: Optional[Dict[str, str]] = ...,
|
||||
cc: Optional[Union[Sequence[str], str]] = ...,
|
||||
reply_to: Optional[Union[List[Optional[str]], str]] = ...,
|
||||
) -> None: ...
|
||||
def get_connection(self, fail_silently: bool = ...) -> BaseEmailBackend: ...
|
||||
def get_connection(self, fail_silently: bool = ...) -> Any: ...
|
||||
def message(self) -> MIMEMixin: ...
|
||||
def recipients(self) -> List[str]: ...
|
||||
def send(self, fail_silently: bool = ...) -> int: ...
|
||||
@@ -92,16 +83,6 @@ class EmailMessage:
|
||||
def attach_file(self, path: str, mimetype: Optional[str] = ...) -> None: ...
|
||||
|
||||
class EmailMultiAlternatives(EmailMessage):
|
||||
attachments: List[Any]
|
||||
bcc: List[Any]
|
||||
body: SafeText
|
||||
cc: List[Any]
|
||||
connection: None
|
||||
extra_headers: Dict[Any, Any]
|
||||
from_email: str
|
||||
reply_to: List[Any]
|
||||
subject: str
|
||||
to: List[str]
|
||||
alternative_subtype: str = ...
|
||||
alternatives: Any = ...
|
||||
def __init__(
|
||||
@@ -111,7 +92,7 @@ class EmailMultiAlternatives(EmailMessage):
|
||||
from_email: Optional[str] = ...,
|
||||
to: Optional[List[str]] = ...,
|
||||
bcc: Optional[List[str]] = ...,
|
||||
connection: Optional[BaseEmailBackend] = ...,
|
||||
connection: Optional[Any] = ...,
|
||||
attachments: None = ...,
|
||||
headers: Optional[Dict[str, str]] = ...,
|
||||
alternatives: Optional[List[Tuple[str, str]]] = ...,
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
class TemplateCommand(BaseCommand):
|
||||
requires_system_checks: bool = ...
|
||||
url_schemes: Any = ...
|
||||
rewrite_template_suffixes: Any = ...
|
||||
def add_arguments(self, parser: CommandParser) -> None: ...
|
||||
app_or_project: Any = ...
|
||||
paths_to_remove: Any = ...
|
||||
verbosity: Any = ...
|
||||
def handle(self, app_or_project: Any, name: Any, target: Optional[Any] = ..., **options: Any): ...
|
||||
def handle_template(self, template: Any, subdir: Any): ...
|
||||
def validate_name(self, name: Any, app_or_project: Any) -> None: ...
|
||||
def download(self, url: Any): ...
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from collections import OrderedDict
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, Union
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, Union, Iterable
|
||||
|
||||
from django.apps.config import AppConfig
|
||||
from django.db.models.base import Model
|
||||
@@ -33,5 +32,5 @@ def serialize(
|
||||
) -> Optional[Union[bytes, str]]: ...
|
||||
def deserialize(format: str, stream_or_string: Any, **options: Any) -> Union[Iterator[Any], Deserializer]: ...
|
||||
def sort_dependencies(
|
||||
app_list: Union[List[Tuple[AppConfig, None]], List[Tuple[str, List[Type[Model]]]]]
|
||||
app_list: Union[Iterable[Tuple[AppConfig, None]], Iterable[Tuple[str, Iterable[Type[Model]]]]]
|
||||
) -> List[Type[Model]]: ...
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from re import RegexFlag
|
||||
from typing import Any, Dict, List, Optional, Union, Pattern
|
||||
from typing import Any, Dict, List, Optional, Union, Pattern, Collection
|
||||
from uuid import UUID
|
||||
|
||||
from django.core.files.base import File
|
||||
@@ -38,7 +38,7 @@ class URLValidator(RegexValidator):
|
||||
tld_re: Any = ...
|
||||
host_re: Any = ...
|
||||
schemes: Any = ...
|
||||
def __init__(self, schemes: Optional[List[str]] = ..., **kwargs: Any) -> None: ...
|
||||
def __init__(self, schemes: Optional[Collection[str]] = ..., **kwargs: Any) -> None: ...
|
||||
|
||||
integer_validator: Any
|
||||
|
||||
@@ -52,7 +52,7 @@ class EmailValidator:
|
||||
literal_regex: Any = ...
|
||||
domain_whitelist: Any = ...
|
||||
def __init__(
|
||||
self, message: Optional[str] = ..., code: Optional[str] = ..., whitelist: Optional[List[str]] = ...
|
||||
self, message: Optional[str] = ..., code: Optional[str] = ..., whitelist: Optional[Collection[str]] = ...
|
||||
) -> None: ...
|
||||
def __call__(self, value: Optional[str]) -> None: ...
|
||||
def validate_domain_part(self, domain_part: str) -> bool: ...
|
||||
@@ -119,7 +119,10 @@ class FileExtensionValidator:
|
||||
code: str = ...
|
||||
allowed_extensions: List[str] = ...
|
||||
def __init__(
|
||||
self, allowed_extensions: Optional[List[str]] = ..., message: Optional[str] = ..., code: Optional[str] = ...
|
||||
self,
|
||||
allowed_extensions: Optional[Collection[str]] = ...,
|
||||
message: Optional[str] = ...,
|
||||
code: Optional[str] = ...,
|
||||
) -> None: ...
|
||||
def __call__(self, value: File) -> None: ...
|
||||
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional
|
||||
|
||||
from django.db.backends.base.client import BaseDatabaseClient
|
||||
from django.db.backends.base.creation import BaseDatabaseCreation
|
||||
from django.db.backends.base.validation import BaseDatabaseValidation
|
||||
from django.db.backends.utils import CursorDebugWrapper, CursorWrapper
|
||||
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
|
||||
from django.db.backends.base.features import BaseDatabaseFeatures
|
||||
|
||||
from django.db.backends.base.introspection import BaseDatabaseIntrospection
|
||||
|
||||
NO_DB_ALIAS: str
|
||||
|
||||
class BaseDatabaseWrapper:
|
||||
@@ -23,7 +30,7 @@ class BaseDatabaseWrapper:
|
||||
queries_limit: int = ...
|
||||
connection: Any = ...
|
||||
settings_dict: Any = ...
|
||||
alias: Any = ...
|
||||
alias: str = ...
|
||||
queries_log: Any = ...
|
||||
force_debug_cursor: bool = ...
|
||||
autocommit: bool = ...
|
||||
@@ -32,18 +39,18 @@ class BaseDatabaseWrapper:
|
||||
savepoint_ids: Any = ...
|
||||
commit_on_exit: bool = ...
|
||||
needs_rollback: bool = ...
|
||||
close_at: Any = ...
|
||||
close_at: Optional[Any] = ...
|
||||
closed_in_transaction: bool = ...
|
||||
errors_occurred: bool = ...
|
||||
allow_thread_sharing: Any = ...
|
||||
run_on_commit: Any = ...
|
||||
allow_thread_sharing: bool = ...
|
||||
run_on_commit: List[Any] = ...
|
||||
run_commit_hooks_on_set_autocommit_on: bool = ...
|
||||
execute_wrappers: Any = ...
|
||||
client: Any = ...
|
||||
creation: Any = ...
|
||||
features: Any = ...
|
||||
introspection: Any = ...
|
||||
validation: Any = ...
|
||||
execute_wrappers: List[Any] = ...
|
||||
client: BaseDatabaseClient = ...
|
||||
creation: BaseDatabaseCreation = ...
|
||||
features: BaseDatabaseFeatures = ...
|
||||
introspection: BaseDatabaseIntrospection = ...
|
||||
validation: BaseDatabaseValidation = ...
|
||||
def __init__(
|
||||
self, settings_dict: Dict[str, Dict[str, str]], alias: str = ..., allow_thread_sharing: bool = ...
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
from typing import Any, List, Optional, Tuple, Type, Union
|
||||
from typing import Any, ContextManager, List, Optional, Sequence, Tuple, Type, Union
|
||||
|
||||
from django.db.backends.ddl_references import Statement
|
||||
from django.db.models.base import Model
|
||||
from django.db.models.fields import Field
|
||||
from django.db.models.indexes import Index
|
||||
|
||||
from django.db.models.fields import Field
|
||||
|
||||
logger: Any
|
||||
|
||||
class BaseDatabaseSchemaEditor:
|
||||
class BaseDatabaseSchemaEditor(ContextManager[Any]):
|
||||
sql_create_table: str = ...
|
||||
sql_rename_table: str = ...
|
||||
sql_retablespace_table: str = ...
|
||||
@@ -27,7 +28,7 @@ class BaseDatabaseSchemaEditor:
|
||||
sql_create_unique: str = ...
|
||||
sql_delete_unique: str = ...
|
||||
sql_create_fk: str = ...
|
||||
sql_create_inline_fk: Any = ...
|
||||
sql_create_inline_fk: str = ...
|
||||
sql_delete_fk: str = ...
|
||||
sql_create_index: str = ...
|
||||
sql_delete_index: str = ...
|
||||
@@ -35,14 +36,14 @@ class BaseDatabaseSchemaEditor:
|
||||
sql_delete_pk: str = ...
|
||||
sql_delete_procedure: str = ...
|
||||
connection: Any = ...
|
||||
collect_sql: Any = ...
|
||||
collect_sql: bool = ...
|
||||
collected_sql: Any = ...
|
||||
atomic_migration: Any = ...
|
||||
def __init__(self, connection: Any, collect_sql: bool = ..., atomic: bool = ...) -> None: ...
|
||||
deferred_sql: Any = ...
|
||||
atomic: Any = ...
|
||||
def __enter__(self) -> BaseDatabaseSchemaEditor: ...
|
||||
def __exit__(self, exc_type: None, exc_value: None, traceback: None) -> None: ...
|
||||
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None: ...
|
||||
def execute(self, sql: Union[Statement, str], params: Optional[Union[List[int], Tuple]] = ...) -> None: ...
|
||||
def quote_name(self, name: str) -> str: ...
|
||||
def column_sql(
|
||||
@@ -59,14 +60,14 @@ class BaseDatabaseSchemaEditor:
|
||||
def alter_unique_together(
|
||||
self,
|
||||
model: Type[Model],
|
||||
old_unique_together: Union[List[List[str]], Tuple[Tuple[str, str]]],
|
||||
new_unique_together: Union[List[List[str]], Tuple[Tuple[str, str]]],
|
||||
old_unique_together: Sequence[Sequence[str]],
|
||||
new_unique_together: Sequence[Sequence[str]],
|
||||
) -> None: ...
|
||||
def alter_index_together(
|
||||
self,
|
||||
model: Type[Model],
|
||||
old_index_together: Union[List[List[str]], List[Tuple[str, str]]],
|
||||
new_index_together: Union[List[List[str]], List[Tuple[str, str]]],
|
||||
old_index_together: Sequence[Sequence[str]],
|
||||
new_index_together: Sequence[Sequence[str]],
|
||||
) -> None: ...
|
||||
def alter_db_table(self, model: Type[Model], old_db_table: str, new_db_table: str) -> None: ...
|
||||
def alter_db_tablespace(self, model: Any, old_db_tablespace: Any, new_db_tablespace: Any) -> None: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.db.backends.base.client import BaseDatabaseClient
|
||||
@@ -10,20 +10,16 @@ def complain(*args: Any, **kwargs: Any) -> Any: ...
|
||||
def ignore(*args: Any, **kwargs: Any) -> None: ...
|
||||
|
||||
class DatabaseOperations(BaseDatabaseOperations):
|
||||
connection: django.db.backends.dummy.base.DatabaseWrapper
|
||||
quote_name: Any = ...
|
||||
|
||||
class DatabaseClient(BaseDatabaseClient):
|
||||
connection: django.db.backends.dummy.base.DatabaseWrapper
|
||||
runshell: Any = ...
|
||||
|
||||
class DatabaseCreation(BaseDatabaseCreation):
|
||||
connection: django.db.backends.dummy.base.DatabaseWrapper
|
||||
create_test_db: Any = ...
|
||||
destroy_test_db: Any = ...
|
||||
|
||||
class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
connection: django.db.backends.dummy.base.DatabaseWrapper
|
||||
get_table_list: Any = ...
|
||||
get_table_description: Any = ...
|
||||
get_relations: Any = ...
|
||||
@@ -31,35 +27,5 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
get_key_columns: Any = ...
|
||||
|
||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||
alias: str
|
||||
allow_thread_sharing: bool
|
||||
autocommit: bool
|
||||
client: django.db.backends.dummy.base.DatabaseClient
|
||||
close_at: None
|
||||
closed_in_transaction: bool
|
||||
commit_on_exit: bool
|
||||
connection: None
|
||||
creation: django.db.backends.dummy.base.DatabaseCreation
|
||||
errors_occurred: bool
|
||||
execute_wrappers: List[Any]
|
||||
features: django.db.backends.dummy.features.DummyDatabaseFeatures
|
||||
force_debug_cursor: bool
|
||||
in_atomic_block: bool
|
||||
introspection: django.db.backends.dummy.base.DatabaseIntrospection
|
||||
needs_rollback: bool
|
||||
ops: django.db.backends.dummy.base.DatabaseOperations
|
||||
queries_log: collections.deque
|
||||
run_commit_hooks_on_set_autocommit_on: bool
|
||||
run_on_commit: List[Any]
|
||||
savepoint_ids: List[Any]
|
||||
savepoint_state: int
|
||||
settings_dict: Dict[str, Optional[Union[Dict[str, None], int, str]]]
|
||||
validation: django.db.backends.base.validation.BaseDatabaseValidation
|
||||
operators: Any = ...
|
||||
ensure_connection: Any = ...
|
||||
client_class: Any = ...
|
||||
creation_class: Any = ...
|
||||
features_class: Any = ...
|
||||
introspection_class: Any = ...
|
||||
ops_class: Any = ...
|
||||
def is_usable(self): ...
|
||||
|
||||
@@ -1,25 +1,3 @@
|
||||
from typing import Any, Optional, Type, Union
|
||||
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.db.models.base import Model
|
||||
from django.db.models.fields import Field
|
||||
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
atomic_migration: bool
|
||||
collect_sql: bool
|
||||
connection: Any
|
||||
sql_delete_table: str = ...
|
||||
sql_create_fk: Any = ...
|
||||
sql_create_inline_fk: str = ...
|
||||
sql_create_unique: str = ...
|
||||
sql_delete_unique: str = ...
|
||||
def __enter__(self) -> DatabaseSchemaEditor: ...
|
||||
def __exit__(self, exc_type: None, exc_value: None, traceback: None) -> None: ...
|
||||
def quote_value(self, value: Optional[Union[int, str]]) -> str: ...
|
||||
def alter_db_table(
|
||||
self, model: Type[Model], old_db_table: str, new_db_table: str, disable_constraints: bool = ...
|
||||
) -> None: ...
|
||||
def alter_field(self, model: Type[Model], old_field: Field, new_field: Field, strict: bool = ...) -> None: ...
|
||||
def delete_model(self, model: Type[Model], handle_autom2m: bool = ...) -> None: ...
|
||||
def add_field(self, model: Type[Model], field: Field) -> None: ...
|
||||
def remove_field(self, model: Type[Model], field: Field) -> None: ...
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): ...
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
from typing import Any, Dict, Optional, Sequence, Set, Tuple, Union
|
||||
|
||||
from django.db.backends.base.base import BaseDatabaseWrapper
|
||||
from django.db.migrations.migration import Migration, SwappableTuple
|
||||
from django.db.migrations.migration import Migration
|
||||
from django.db.migrations.state import ProjectState
|
||||
|
||||
from django.db import DefaultConnectionProxy
|
||||
|
||||
MIGRATIONS_MODULE_NAME: str
|
||||
|
||||
class MigrationLoader:
|
||||
@@ -13,12 +10,7 @@ class MigrationLoader:
|
||||
disk_migrations: Dict[Tuple[str, str], Migration] = ...
|
||||
applied_migrations: None = ...
|
||||
ignore_no_migrations: bool = ...
|
||||
def __init__(
|
||||
self,
|
||||
connection: Optional[Union[DefaultConnectionProxy, BaseDatabaseWrapper]],
|
||||
load: bool = ...,
|
||||
ignore_no_migrations: bool = ...,
|
||||
) -> None: ...
|
||||
def __init__(self, connection: Any, load: bool = ..., ignore_no_migrations: bool = ...) -> None: ...
|
||||
@classmethod
|
||||
def migrations_module(cls, app_label: str) -> Tuple[Optional[str], bool]: ...
|
||||
unmigrated_apps: Set[str] = ...
|
||||
@@ -26,7 +18,7 @@ class MigrationLoader:
|
||||
def load_disk(self) -> None: ...
|
||||
def get_migration(self, app_label: str, name_prefix: str) -> Migration: ...
|
||||
def get_migration_by_prefix(self, app_label: str, name_prefix: str) -> Migration: ...
|
||||
def check_key(self, key: Union[Tuple[str, str], SwappableTuple], current_app: str) -> Optional[Tuple[str, str]]: ...
|
||||
def check_key(self, key: Tuple[str, str], current_app: str) -> Optional[Tuple[str, str]]: ...
|
||||
def add_internal_dependencies(self, key: Tuple[str, str], migration: Migration) -> None: ...
|
||||
def add_external_dependencies(self, key: Tuple[str, str], migration: Migration) -> None: ...
|
||||
graph: Any = ...
|
||||
@@ -35,5 +27,5 @@ class MigrationLoader:
|
||||
def check_consistent_history(self, connection: Any) -> None: ...
|
||||
def detect_conflicts(self) -> Dict[str, Set[str]]: ...
|
||||
def project_state(
|
||||
self, nodes: Optional[Tuple[str, str], Sequence[Tuple[str, str]]] = ..., at_end: bool = ...
|
||||
self, nodes: Optional[Union[Tuple[str, str], Sequence[Tuple[str, str]]]] = ..., at_end: bool = ...
|
||||
) -> ProjectState: ...
|
||||
|
||||
@@ -21,7 +21,7 @@ class Migration:
|
||||
self, project_state: ProjectState, schema_editor: BaseDatabaseSchemaEditor, collect_sql: bool = ...
|
||||
) -> ProjectState: ...
|
||||
|
||||
class SwappableTuple(tuple):
|
||||
class SwappableTuple(Tuple[str, str]):
|
||||
setting: str = ...
|
||||
def __new__(cls, value: Tuple[str, str], setting: str) -> SwappableTuple: ...
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ _Self = TypeVar("_Self", bound="Model")
|
||||
|
||||
class Model(metaclass=ModelBase):
|
||||
class DoesNotExist(Exception): ...
|
||||
class MultipleObjectsReturned(Exception): ...
|
||||
class Meta: ...
|
||||
_meta: Any
|
||||
_default_manager: Manager[Model]
|
||||
@@ -15,6 +16,7 @@ class Model(metaclass=ModelBase):
|
||||
def __init__(self: _Self, *args, **kwargs) -> None: ...
|
||||
def delete(self, using: Any = ..., keep_parents: bool = ...) -> Tuple[int, Dict[str, int]]: ...
|
||||
def full_clean(self, exclude: Optional[List[str]] = ..., validate_unique: bool = ...) -> None: ...
|
||||
def clean(self) -> None: ...
|
||||
def clean_fields(self, exclude: List[str] = ...) -> None: ...
|
||||
def validate_unique(self, exclude: List[str] = ...) -> None: ...
|
||||
def save(
|
||||
@@ -34,6 +36,7 @@ class Model(metaclass=ModelBase):
|
||||
): ...
|
||||
def refresh_from_db(self: _Self, using: Optional[str] = ..., fields: Optional[List[str]] = ...) -> _Self: ...
|
||||
def get_deferred_fields(self) -> Set[str]: ...
|
||||
def __getstate__(self) -> dict: ...
|
||||
|
||||
class ModelStateFieldsCacheDescriptor: ...
|
||||
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Type, Union, TypeVar
|
||||
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Type, TypeVar, Union
|
||||
|
||||
from django.db.models.lookups import Lookup
|
||||
from django.db.models.sql.compiler import SQLCompiler
|
||||
|
||||
from django.db.models import Q, QuerySet
|
||||
from django.db.models.fields import Field, FloatField
|
||||
from django.db.models.sql import Query
|
||||
from django.db.models.fields import Field
|
||||
|
||||
_OutputField = Union[Field, str]
|
||||
|
||||
class SQLiteNumericMixin:
|
||||
def as_sqlite(self, compiler: SQLCompiler, connection: Any, **extra_context: Any) -> Tuple[str, List[float]]: ...
|
||||
|
||||
_SelfCombinable = TypeVar("_SelfCombinable", bound="Combinable")
|
||||
_Self = TypeVar("_Self")
|
||||
|
||||
class Combinable:
|
||||
ADD: str = ...
|
||||
@@ -27,22 +25,20 @@ class Combinable:
|
||||
BITOR: str = ...
|
||||
BITLEFTSHIFT: str = ...
|
||||
BITRIGHTSHIFT: str = ...
|
||||
def __neg__(self: _SelfCombinable) -> _SelfCombinable: ...
|
||||
def __add__(
|
||||
self: _SelfCombinable, other: Optional[Union[timedelta, Combinable, float, str]]
|
||||
) -> _SelfCombinable: ...
|
||||
def __sub__(self: _SelfCombinable, other: Union[timedelta, Combinable, float]) -> _SelfCombinable: ...
|
||||
def __mul__(self: _SelfCombinable, other: Union[timedelta, Combinable, float]) -> _SelfCombinable: ...
|
||||
def __truediv__(self: _SelfCombinable, other: Union[Combinable, float]) -> _SelfCombinable: ...
|
||||
def __itruediv__(self: _SelfCombinable, other: Union[Combinable, float]) -> _SelfCombinable: ...
|
||||
def __mod__(self: _SelfCombinable, other: Union[int, Combinable]) -> _SelfCombinable: ...
|
||||
def __pow__(self: _SelfCombinable, other: Union[float, Combinable]) -> _SelfCombinable: ...
|
||||
def __and__(self: _SelfCombinable, other: Combinable) -> _SelfCombinable: ...
|
||||
def bitand(self: _SelfCombinable, other: int) -> _SelfCombinable: ...
|
||||
def bitleftshift(self: _SelfCombinable, other: int) -> _SelfCombinable: ...
|
||||
def bitrightshift(self: _SelfCombinable, other: int) -> _SelfCombinable: ...
|
||||
def __or__(self: _SelfCombinable, other: Combinable) -> _SelfCombinable: ...
|
||||
def bitor(self: _SelfCombinable, other: int) -> _SelfCombinable: ...
|
||||
def __neg__(self: _Self) -> _Self: ...
|
||||
def __add__(self: _Self, other: Optional[Union[timedelta, Combinable, float, str]]) -> _Self: ...
|
||||
def __sub__(self: _Self, other: Union[timedelta, Combinable, float]) -> _Self: ...
|
||||
def __mul__(self: _Self, other: Union[timedelta, Combinable, float]) -> _Self: ...
|
||||
def __truediv__(self: _Self, other: Union[Combinable, float]) -> _Self: ...
|
||||
def __itruediv__(self: _Self, other: Union[Combinable, float]) -> _Self: ...
|
||||
def __mod__(self: _Self, other: Union[int, Combinable]) -> _Self: ...
|
||||
def __pow__(self: _Self, other: Union[float, Combinable]) -> _Self: ...
|
||||
def __and__(self: _Self, other: Combinable) -> _Self: ...
|
||||
def bitand(self: _Self, other: int) -> _Self: ...
|
||||
def bitleftshift(self: _Self, other: int) -> _Self: ...
|
||||
def bitrightshift(self: _Self, other: int) -> _Self: ...
|
||||
def __or__(self: _Self, other: Combinable) -> _Self: ...
|
||||
def bitor(self: _Self, other: int) -> _Self: ...
|
||||
def __radd__(self, other: Optional[Union[datetime, float, Combinable]]) -> Combinable: ...
|
||||
def __rsub__(self, other: Union[float, Combinable]) -> Combinable: ...
|
||||
def __rmul__(self, other: Union[float, Combinable]) -> Combinable: ...
|
||||
@@ -52,43 +48,45 @@ class Combinable:
|
||||
def __rand__(self, other: Any) -> Combinable: ...
|
||||
def __ror__(self, other: Any) -> Combinable: ...
|
||||
|
||||
_SelfBaseExpression = TypeVar("_SelfBaseExpression", bound="BaseExpression")
|
||||
|
||||
class BaseExpression:
|
||||
is_summary: bool = ...
|
||||
filterable: bool = ...
|
||||
window_compatible: bool = ...
|
||||
output_field: Any
|
||||
def __init__(self, output_field: Optional[_OutputField] = ...) -> None: ...
|
||||
def get_db_converters(self, connection: Any) -> List[Callable]: ...
|
||||
def get_source_expressions(self) -> List[Any]: ...
|
||||
def set_source_expressions(self, exprs: List[Any]) -> None: ...
|
||||
def set_source_expressions(self, exprs: Sequence[Combinable]) -> None: ...
|
||||
@property
|
||||
def contains_aggregate(self) -> bool: ...
|
||||
@property
|
||||
def contains_over_clause(self) -> bool: ...
|
||||
@property
|
||||
def contains_column_references(self) -> bool: ...
|
||||
def resolve_expression(
|
||||
self,
|
||||
self: _Self,
|
||||
query: Any = ...,
|
||||
allow_joins: bool = ...,
|
||||
reuse: Optional[Set[str]] = ...,
|
||||
summarize: bool = ...,
|
||||
for_save: bool = ...,
|
||||
) -> BaseExpression: ...
|
||||
) -> _Self: ...
|
||||
@property
|
||||
def field(self) -> Field: ...
|
||||
@property
|
||||
def output_field(self) -> Field: ...
|
||||
@property
|
||||
def convert_value(self) -> Callable: ...
|
||||
def get_lookup(self, lookup: str) -> Optional[Type[Lookup]]: ...
|
||||
def get_transform(self, name: str) -> Optional[Type[Expression]]: ...
|
||||
def relabeled_clone(self, change_map: Dict[Optional[str], str]) -> Expression: ...
|
||||
def copy(self) -> BaseExpression: ...
|
||||
def get_group_by_cols(self: _SelfBaseExpression) -> List[_SelfBaseExpression]: ...
|
||||
def get_group_by_cols(self: _Self) -> List[_Self]: ...
|
||||
def get_source_fields(self) -> List[Optional[Field]]: ...
|
||||
def asc(self, **kwargs: Any) -> Expression: ...
|
||||
def desc(self, **kwargs: Any) -> Expression: ...
|
||||
def reverse_ordering(self): ...
|
||||
def flatten(self) -> Iterator[Expression]: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def deconstruct(self) -> Any: ...
|
||||
def as_sqlite(self, compiler: SQLCompiler, connection: Any) -> Any: ...
|
||||
def as_sql(self, compiler: SQLCompiler, connection: Any, **extra_context: Any) -> Any: ...
|
||||
@@ -105,28 +103,18 @@ class CombinedExpression(SQLiteNumericMixin, Expression):
|
||||
def __init__(
|
||||
self, lhs: Combinable, connector: str, rhs: Combinable, output_field: Optional[_OutputField] = ...
|
||||
) -> None: ...
|
||||
def get_source_expressions(self) -> Union[List[Combinable], List[SQLiteNumericMixin]]: ...
|
||||
def set_source_expressions(self, exprs: List[Combinable]) -> None: ...
|
||||
def resolve_expression(
|
||||
self,
|
||||
query: Any = ...,
|
||||
allow_joins: bool = ...,
|
||||
reuse: Optional[Set[str]] = ...,
|
||||
summarize: bool = ...,
|
||||
for_save: bool = ...,
|
||||
) -> CombinedExpression: ...
|
||||
|
||||
class F(Combinable):
|
||||
name: str
|
||||
def __init__(self, name: str): ...
|
||||
def resolve_expression(
|
||||
self,
|
||||
self: _Self,
|
||||
query: Any = ...,
|
||||
allow_joins: bool = ...,
|
||||
reuse: Optional[Set[str]] = ...,
|
||||
summarize: bool = ...,
|
||||
for_save: bool = ...,
|
||||
) -> Expression: ...
|
||||
) -> _Self: ...
|
||||
def asc(self, **kwargs) -> OrderBy: ...
|
||||
def desc(self, **kwargs) -> OrderBy: ...
|
||||
def deconstruct(self) -> Any: ...
|
||||
@@ -141,8 +129,6 @@ class Subquery(Expression):
|
||||
def __init__(self, queryset: QuerySet, output_field: Optional[_OutputField] = ..., **extra: Any) -> None: ...
|
||||
|
||||
class Exists(Subquery):
|
||||
extra: Dict[Any, Any]
|
||||
template: str = ...
|
||||
negated: bool = ...
|
||||
def __init__(self, *args: Any, negated: bool = ..., **kwargs: Any) -> None: ...
|
||||
def __invert__(self) -> Exists: ...
|
||||
@@ -162,30 +148,19 @@ class Value(Expression):
|
||||
def __init__(self, value: Any, output_field: Optional[_OutputField] = ...) -> None: ...
|
||||
|
||||
class RawSQL(Expression):
|
||||
output_field: Field
|
||||
params: List[Any]
|
||||
sql: str
|
||||
def __init__(self, sql: str, params: Sequence[Any], output_field: Optional[_OutputField] = ...) -> None: ...
|
||||
|
||||
class Func(SQLiteNumericMixin, Expression):
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
template: str = ...
|
||||
arg_joiner: str = ...
|
||||
arity: int = ...
|
||||
source_expressions: List[Expression] = ...
|
||||
source_expressions: List[Combinable] = ...
|
||||
extra: Dict[Any, Any] = ...
|
||||
def __init__(self, *expressions: Any, output_field: Optional[_OutputField] = ..., **extra: Any) -> None: ...
|
||||
def get_source_expressions(self) -> List[Combinable]: ...
|
||||
def set_source_expressions(self, exprs: List[Expression]) -> None: ...
|
||||
def resolve_expression(
|
||||
self,
|
||||
query: Query = ...,
|
||||
allow_joins: bool = ...,
|
||||
reuse: Optional[Set[Any]] = ...,
|
||||
summarize: bool = ...,
|
||||
for_save: bool = ...,
|
||||
) -> Func: ...
|
||||
def copy(self) -> Func: ...
|
||||
|
||||
class When(Expression):
|
||||
template: str = ...
|
||||
@@ -205,8 +180,6 @@ class Case(Expression):
|
||||
|
||||
class ExpressionWrapper(Expression):
|
||||
def __init__(self, expression: Union[Q, Combinable], output_field: _OutputField): ...
|
||||
def set_source_expressions(self, exprs: Sequence[Expression]) -> None: ...
|
||||
def get_source_expressions(self) -> List[Expression]: ...
|
||||
|
||||
class Col(Expression):
|
||||
def __init__(self, alias: str, target: str, output_field: Optional[_OutputField] = ...): ...
|
||||
@@ -214,8 +187,7 @@ class Col(Expression):
|
||||
class ExpressionList(Func):
|
||||
def __init__(self, *expressions: Union[BaseExpression, Combinable], **extra: Any) -> None: ...
|
||||
|
||||
class Random(Expression):
|
||||
output_field: FloatField
|
||||
class Random(Expression): ...
|
||||
|
||||
class Ref(Expression):
|
||||
def __init__(self, refs: str, source: Expression): ...
|
||||
|
||||
@@ -1,51 +1,11 @@
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
from typing import Any, Callable, Dict, List, Union
|
||||
|
||||
from django.db.models.expressions import Combinable, Expression
|
||||
from typing import Any, Union
|
||||
|
||||
from django.db.models import Func
|
||||
from django.db.models.fields import Field
|
||||
|
||||
class Cast(Func):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
extra: Dict[Any, Any]
|
||||
is_summary: bool
|
||||
output_field: Field
|
||||
source_expressions: List[Combinable]
|
||||
function: str = ...
|
||||
template: str = ...
|
||||
def __init__(self, expression: Union[date, Decimal, Expression, str], output_field: Union[str, Field]) -> None: ...
|
||||
def __init__(self, expression: Any, output_field: Union[str, Field]) -> None: ...
|
||||
|
||||
class Coalesce(Func):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
extra: Dict[Any, Any]
|
||||
is_summary: bool
|
||||
output_field: Field
|
||||
source_expressions: List[Combinable]
|
||||
function: str = ...
|
||||
def __init__(self, *expressions: Any, **extra: Any) -> None: ...
|
||||
|
||||
class Greatest(Func):
|
||||
contains_aggregate: bool
|
||||
contains_over_clause: bool
|
||||
convert_value: Callable
|
||||
extra: Dict[Any, Any]
|
||||
is_summary: bool
|
||||
output_field: Field
|
||||
source_expressions: List[Combinable]
|
||||
function: str = ...
|
||||
def __init__(self, *expressions: Any, **extra: Any) -> None: ...
|
||||
|
||||
class Least(Func):
|
||||
contains_aggregate: bool
|
||||
contains_over_clause: bool
|
||||
convert_value: Callable
|
||||
extra: Dict[Any, Any]
|
||||
is_summary: bool
|
||||
output_field: Field
|
||||
source_expressions: List[Combinable]
|
||||
function: str = ...
|
||||
def __init__(self, *expressions: Any, **extra: Any) -> None: ...
|
||||
class Coalesce(Func): ...
|
||||
class Greatest(Func): ...
|
||||
class Least(Func): ...
|
||||
|
||||
@@ -1,105 +1,47 @@
|
||||
from typing import Any, List, Optional, Tuple, Union, Callable
|
||||
from typing import Any, List, Optional, Tuple, Union
|
||||
|
||||
from django.db.backends.sqlite3.base import DatabaseWrapper
|
||||
from django.db.models.expressions import Combinable, Expression, Value
|
||||
from django.db.models.sql.compiler import SQLCompiler
|
||||
|
||||
from django.db.models import Func, Transform
|
||||
from django.db.models.fields import Field
|
||||
|
||||
class BytesToCharFieldConversionMixin:
|
||||
def convert_value(
|
||||
self, value: str, expression: BytesToCharFieldConversionMixin, connection: DatabaseWrapper
|
||||
) -> str: ...
|
||||
|
||||
class Chr(Transform):
|
||||
contains_aggregate: bool
|
||||
lookup_name: str = ...
|
||||
class BytesToCharFieldConversionMixin: ...
|
||||
class Chr(Transform): ...
|
||||
|
||||
class ConcatPair(Func):
|
||||
contains_aggregate: bool
|
||||
def coalesce(self) -> ConcatPair: ...
|
||||
|
||||
class Concat(Func):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
class Concat(Func): ...
|
||||
|
||||
class Left(Func):
|
||||
contains_aggregate: bool
|
||||
contains_over_clause: bool
|
||||
convert_value: Callable
|
||||
output_field: Field
|
||||
def __init__(self, expression: str, length: Union[Value, int], **extra: Any) -> None: ...
|
||||
def get_substr(self) -> Substr: ...
|
||||
def use_substr(
|
||||
self, compiler: SQLCompiler, connection: DatabaseWrapper, **extra_context: Any
|
||||
) -> Tuple[str, List[int]]: ...
|
||||
as_oracle: Any = ...
|
||||
as_sqlite: Any = ...
|
||||
|
||||
class Length(Transform):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
lookup_name: str = ...
|
||||
|
||||
class Lower(Transform):
|
||||
contains_aggregate: bool
|
||||
contains_column_references: bool
|
||||
contains_over_clause: bool
|
||||
convert_value: Callable
|
||||
lookup_name: str = ...
|
||||
class Length(Transform): ...
|
||||
class Lower(Transform): ...
|
||||
|
||||
class LPad(BytesToCharFieldConversionMixin, Func):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
def __init__(self, expression: str, length: Union[Length, int], fill_text: Value = ..., **extra: Any) -> None: ...
|
||||
|
||||
class LTrim(Transform):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
lookup_name: str = ...
|
||||
|
||||
class Ord(Transform):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
lookup_name: str = ...
|
||||
def as_mysql(self, compiler: Any, connection: Any, **extra_context: Any): ...
|
||||
class LTrim(Transform): ...
|
||||
class Ord(Transform): ...
|
||||
|
||||
class Repeat(BytesToCharFieldConversionMixin, Func):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
output_field: django.db.models.fields.CharField
|
||||
def __init__(self, expression: Union[Value, str], number: Union[Length, int], **extra: Any) -> None: ...
|
||||
def as_oracle(self, compiler: Any, connection: Any, **extra_context: Any): ...
|
||||
|
||||
class Replace(Func):
|
||||
contains_aggregate: bool
|
||||
contains_over_clause: bool
|
||||
convert_value: Callable
|
||||
output_field: Field
|
||||
def __init__(self, expression: Combinable, text: Value, replacement: Value = ..., **extra: Any) -> None: ...
|
||||
|
||||
class Right(Left): ...
|
||||
|
||||
class RPad(LPad):
|
||||
output_field: Field
|
||||
|
||||
class RTrim(Transform):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
lookup_name: str = ...
|
||||
|
||||
class StrIndex(Func):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
output_field: Any = ...
|
||||
def as_postgresql(self, compiler: Any, connection: Any): ...
|
||||
class RPad(LPad): ...
|
||||
class RTrim(Transform): ...
|
||||
class StrIndex(Func): ...
|
||||
|
||||
class Substr(Func):
|
||||
contains_aggregate: bool
|
||||
contains_over_clause: bool
|
||||
convert_value: Callable
|
||||
output_field: Field
|
||||
def __init__(
|
||||
self,
|
||||
expression: Union[Expression, str],
|
||||
@@ -108,13 +50,5 @@ class Substr(Func):
|
||||
**extra: Any
|
||||
) -> None: ...
|
||||
|
||||
class Trim(Transform):
|
||||
contains_aggregate: bool
|
||||
convert_value: Callable
|
||||
lookup_name: str = ...
|
||||
|
||||
class Upper(Transform):
|
||||
contains_aggregate: bool
|
||||
contains_over_clause: bool
|
||||
convert_value: Callable
|
||||
lookup_name: str = ...
|
||||
class Trim(Transform): ...
|
||||
class Upper(Transform): ...
|
||||
|
||||
@@ -1,69 +1,26 @@
|
||||
from typing import Any, Optional, Dict, List
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.db.models import Func
|
||||
|
||||
class CumeDist(Func):
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
output_field: Any = ...
|
||||
window_compatible: bool = ...
|
||||
|
||||
class DenseRank(Func):
|
||||
name: str = ...
|
||||
output_field: Any = ...
|
||||
window_compatible: bool = ...
|
||||
|
||||
class FirstValue(Func):
|
||||
name: str = ...
|
||||
window_compatible: bool = ...
|
||||
class CumeDist(Func): ...
|
||||
class DenseRank(Func): ...
|
||||
class FirstValue(Func): ...
|
||||
|
||||
class LagLeadFunction(Func):
|
||||
window_compatible: bool = ...
|
||||
def __init__(
|
||||
self, expression: Optional[str], offset: int = ..., default: Optional[int] = ..., **extra: Any
|
||||
) -> None: ...
|
||||
|
||||
class Lag(LagLeadFunction):
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
|
||||
class LastValue(Func):
|
||||
arity: int = ...
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
window_compatible: bool = ...
|
||||
|
||||
class Lead(LagLeadFunction):
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
class Lag(LagLeadFunction): ...
|
||||
class LastValue(Func): ...
|
||||
class Lead(LagLeadFunction): ...
|
||||
|
||||
class NthValue(Func):
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
window_compatible: bool = ...
|
||||
def __init__(self, expression: Optional[str], nth: int = ..., **extra: Any) -> Any: ...
|
||||
def __init__(self, expression: Optional[str], nth: int = ..., **extra: Any) -> None: ...
|
||||
|
||||
class Ntile(Func):
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
output_field: Any = ...
|
||||
window_compatible: bool = ...
|
||||
def __init__(self, num_buckets: int = ..., **extra: Any) -> Any: ...
|
||||
def __init__(self, num_buckets: int = ..., **extra: Any) -> None: ...
|
||||
|
||||
class PercentRank(Func):
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
output_field: Any = ...
|
||||
window_compatible: bool = ...
|
||||
|
||||
class Rank(Func):
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
output_field: Any = ...
|
||||
window_compatible: bool = ...
|
||||
|
||||
class RowNumber(Func):
|
||||
function: str = ...
|
||||
name: str = ...
|
||||
output_field: Any = ...
|
||||
window_compatible: bool = ...
|
||||
class PercentRank(Func): ...
|
||||
class Rank(Func): ...
|
||||
class RowNumber(Func): ...
|
||||
|
||||
@@ -22,7 +22,6 @@ from typing import (
|
||||
from django.db.models.base import Model
|
||||
from django.db.models.expressions import Combinable as Combinable, F as F
|
||||
from django.db.models.sql.query import Query, RawQuery
|
||||
from typing_extensions import Literal
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import Manager
|
||||
@@ -98,19 +97,12 @@ class QuerySet(Generic[_T, _Row], Collection[_Row], Sized):
|
||||
def raw(
|
||||
self, raw_query: str, params: Any = ..., translations: Optional[Dict[str, str]] = ..., using: None = ...
|
||||
) -> RawQuerySet: ...
|
||||
# The type of values may be overridden to be more specific in the mypy plugin, depending on the fields param
|
||||
def values(self, *fields: Union[str, Combinable], **expressions: Any) -> QuerySet[_T, Dict[str, Any]]: ...
|
||||
@overload
|
||||
# The type of values_list may be overridden to be more specific in the mypy plugin, depending on the fields param
|
||||
def values_list(
|
||||
self, *fields: Union[str, Combinable], flat: Literal[False] = ..., named: Literal[True]
|
||||
) -> QuerySet[_T, NamedTuple]: ...
|
||||
@overload
|
||||
def values_list(
|
||||
self, *fields: Union[str, Combinable], flat: Literal[True], named: Literal[False] = ...
|
||||
self, *fields: Union[str, Combinable], flat: bool = ..., named: bool = ...
|
||||
) -> QuerySet[_T, Any]: ...
|
||||
@overload
|
||||
def values_list(
|
||||
self, *fields: Union[str, Combinable], flat: Literal[False] = ..., named: Literal[False] = ...
|
||||
) -> QuerySet[_T, Tuple]: ...
|
||||
def dates(self, field_name: str, kind: str, order: str = ...) -> QuerySet[_T, datetime.date]: ...
|
||||
def datetimes(
|
||||
self, field_name: str, kind: str, order: str = ..., tzinfo: None = ...
|
||||
|
||||
@@ -6,6 +6,18 @@ from .models import (
|
||||
ModelForm as ModelForm,
|
||||
ModelChoiceField as ModelChoiceField,
|
||||
ModelMultipleChoiceField as ModelMultipleChoiceField,
|
||||
model_to_dict as model_to_dict,
|
||||
BaseModelForm as BaseModelForm,
|
||||
BaseInlineFormSet as BaseInlineFormSet,
|
||||
BaseModelFormSet as BaseModelFormSet,
|
||||
fields_for_model as fields_for_model,
|
||||
inlineformset_factory as inlineformset_factory,
|
||||
modelform_factory as modelform_factory,
|
||||
InlineForeignKeyField as InlineForeignKeyField,
|
||||
ModelChoiceIterator as ModelChoiceIterator,
|
||||
ModelFormMetaclass as ModelFormMetaclass,
|
||||
ModelFormOptions as ModelFormOptions,
|
||||
modelformset_factory as modelformset_factory,
|
||||
)
|
||||
|
||||
from .widgets import (
|
||||
@@ -68,3 +80,5 @@ from .fields import (
|
||||
TypedChoiceField as TypedChoiceField,
|
||||
TypedMultipleChoiceField as TypedMultipleChoiceField,
|
||||
)
|
||||
|
||||
from .boundfield import BoundField as BoundField, BoundWidget as BoundWidget
|
||||
|
||||
@@ -21,7 +21,7 @@ class BaseForm:
|
||||
is_bound: bool = ...
|
||||
data: Dict[str, Any] = ...
|
||||
files: Optional[Dict[str, Any]] = ...
|
||||
auto_id: Any = ...
|
||||
auto_id: str = ...
|
||||
initial: Dict[str, Any] = ...
|
||||
error_class: Type[ErrorList] = ...
|
||||
prefix: str = ...
|
||||
@@ -59,7 +59,7 @@ class BaseForm:
|
||||
def add_error(self, field: Optional[str], error: Union[ValidationError, str]) -> None: ...
|
||||
def has_error(self, field: Any, code: Optional[Any] = ...): ...
|
||||
def full_clean(self) -> None: ...
|
||||
def clean(self) -> Dict[str, Optional[Union[datetime, SimpleUploadedFile, QuerySet, str]]]: ...
|
||||
def clean(self) -> Dict[str, Any]: ...
|
||||
def has_changed(self) -> bool: ...
|
||||
def changed_data(self) -> List[str]: ...
|
||||
@property
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
from collections import OrderedDict
|
||||
from datetime import date, datetime
|
||||
from typing import Any, Callable, Dict, Iterator, List, MutableMapping, Optional, Sequence, Tuple, Type, Union, Mapping
|
||||
from datetime import datetime
|
||||
from typing import Any, Callable, Dict, Iterator, List, Mapping, MutableMapping, Optional, Sequence, Tuple, Type, Union
|
||||
from unittest.mock import MagicMock
|
||||
from uuid import UUID
|
||||
|
||||
from django.core.files.base import File
|
||||
from django.db import models
|
||||
from django.db.models import ForeignKey
|
||||
from django.db.models.base import Model
|
||||
from django.db.models.manager import Manager
|
||||
from django.db.models.query import QuerySet
|
||||
@@ -18,6 +15,9 @@ from django.forms.utils import ErrorList
|
||||
from django.forms.widgets import Input, Widget
|
||||
from typing_extensions import Literal
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import ForeignKey
|
||||
|
||||
ALL_FIELDS: str
|
||||
|
||||
_Fields = Union[List[Union[Callable, str]], Sequence[str], Literal["__all__"]]
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
from datetime import time
|
||||
from decimal import Decimal
|
||||
from itertools import chain
|
||||
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Sequence, Set, Tuple, Type, Union
|
||||
from typing import Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Sequence, Set, Tuple, Type, Union
|
||||
|
||||
from django.core.files.base import File
|
||||
from django.db.models.fields.files import FieldFile
|
||||
from django.forms.renderers import EngineMixin
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
from django.utils.safestring import SafeText
|
||||
|
||||
_OptAttrs = Dict[str, str]
|
||||
_OptAttrs = Dict[str, Any]
|
||||
|
||||
class MediaOrderConflictWarning(RuntimeWarning): ...
|
||||
|
||||
@@ -38,31 +35,21 @@ class Widget:
|
||||
is_localized: bool = ...
|
||||
is_required: bool = ...
|
||||
supports_microseconds: bool = ...
|
||||
attrs: Dict[str, Any] = ...
|
||||
def __init__(self, attrs: Optional[Dict[str, Any]] = ...) -> None: ...
|
||||
attrs: _OptAttrs = ...
|
||||
def __init__(self, attrs: Optional[_OptAttrs] = ...) -> None: ...
|
||||
@property
|
||||
def is_hidden(self) -> bool: ...
|
||||
def subwidgets(
|
||||
self, name: str, value: Optional[List[str]], attrs: Dict[str, bool] = ...
|
||||
) -> Iterator[Dict[str, Any]]: ...
|
||||
def subwidgets(self, name: str, value: Optional[List[str]], attrs: _OptAttrs = ...) -> Iterator[Dict[str, Any]]: ...
|
||||
def format_value(self, value: Any) -> Optional[str]: ...
|
||||
def get_context(self, name: str, value: Any, attrs: Optional[Dict[str, Union[bool, str]]]) -> Dict[str, Any]: ...
|
||||
def get_context(self, name: str, value: Any, attrs: Optional[_OptAttrs]) -> Dict[str, Any]: ...
|
||||
def render(
|
||||
self,
|
||||
name: str,
|
||||
value: Any,
|
||||
attrs: Optional[Dict[str, Union[bool, str]]] = ...,
|
||||
renderer: Optional[EngineMixin] = ...,
|
||||
self, name: str, value: Any, attrs: Optional[_OptAttrs] = ..., renderer: Optional[EngineMixin] = ...
|
||||
) -> SafeText: ...
|
||||
def build_attrs(
|
||||
self, base_attrs: Dict[str, Union[float, str]], extra_attrs: Optional[Dict[str, Union[bool, str]]] = ...
|
||||
self, base_attrs: _OptAttrs, extra_attrs: Optional[_OptAttrs] = ...
|
||||
) -> Dict[str, Union[Decimal, float, str]]: ...
|
||||
def value_from_datadict(
|
||||
self, data: dict, files: Union[Dict[str, Iterable[Any]], MultiValueDict], name: str
|
||||
) -> Any: ...
|
||||
def value_omitted_from_data(
|
||||
self, data: Dict[str, Any], files: Union[Dict[str, Iterable[Any]], MultiValueDict], name: str
|
||||
) -> bool: ...
|
||||
def value_from_datadict(self, data: Dict[str, Any], files: Mapping[str, Iterable[Any]], name: str) -> Any: ...
|
||||
def value_omitted_from_data(self, data: Dict[str, Any], files: Mapping[str, Iterable[Any]], name: str) -> bool: ...
|
||||
def id_for_label(self, id_: str) -> str: ...
|
||||
def use_required_attribute(self, initial: Any) -> bool: ...
|
||||
|
||||
@@ -94,14 +81,12 @@ class ClearableFileInput(FileInput):
|
||||
def clear_checkbox_name(self, name: str) -> str: ...
|
||||
def clear_checkbox_id(self, name: str) -> str: ...
|
||||
def is_initial(self, value: Optional[Union[File, str]]) -> bool: ...
|
||||
def use_required_attribute(self, initial: Optional[Union[FieldFile, str]]) -> bool: ...
|
||||
|
||||
class Textarea(Widget):
|
||||
template_name: str = ...
|
||||
|
||||
class DateTimeBaseInput(TextInput):
|
||||
format_key: str = ...
|
||||
supports_microseconds: bool = ...
|
||||
format: Optional[str] = ...
|
||||
def __init__(self, attrs: Optional[_OptAttrs] = ..., format: Optional[str] = ...): ...
|
||||
|
||||
@@ -128,7 +113,7 @@ class ChoiceWidget(Widget):
|
||||
def create_option(
|
||||
self,
|
||||
name: str,
|
||||
value: Union[time, int, str],
|
||||
value: Any,
|
||||
label: Union[int, str],
|
||||
selected: Union[Set[str], bool],
|
||||
index: int,
|
||||
@@ -137,13 +122,7 @@ class ChoiceWidget(Widget):
|
||||
) -> Dict[str, Any]: ...
|
||||
def id_for_label(self, id_: str, index: str = ...) -> str: ...
|
||||
|
||||
class Select(ChoiceWidget):
|
||||
option_template_name: str = ...
|
||||
add_id_index: bool = ...
|
||||
checked_attribute: Any = ...
|
||||
option_inherits_attrs: bool = ...
|
||||
def use_required_attribute(self, initial: Any) -> bool: ...
|
||||
|
||||
class Select(ChoiceWidget): ...
|
||||
class NullBooleanSelect(Select): ...
|
||||
|
||||
class SelectMultiple(Select):
|
||||
@@ -154,40 +133,26 @@ class RadioSelect(ChoiceWidget):
|
||||
option_template_name: str = ...
|
||||
|
||||
class CheckboxSelectMultiple(ChoiceWidget):
|
||||
allow_multiple_selected: bool = ...
|
||||
option_template_name: str = ...
|
||||
def use_required_attribute(self, initial: Optional[List[str]]) -> bool: ...
|
||||
def id_for_label(self, id_: str, index: Optional[str] = ...) -> str: ...
|
||||
|
||||
class MultiWidget(Widget):
|
||||
template_name: str = ...
|
||||
widgets: List[Widget] = ...
|
||||
def __init__(self, widgets: Sequence[Union[Widget, Type[Widget]]], attrs: Optional[_OptAttrs] = ...) -> None: ...
|
||||
@property
|
||||
def is_hidden(self) -> bool: ...
|
||||
def decompress(self, value: Any) -> Optional[Any]: ...
|
||||
media: Any = ...
|
||||
|
||||
class SplitDateTimeWidget(MultiWidget):
|
||||
supports_microseconds: bool = ...
|
||||
def __init__(
|
||||
self,
|
||||
attrs: Optional[Dict[str, str]] = ...,
|
||||
attrs: Optional[_OptAttrs] = ...,
|
||||
date_format: Optional[str] = ...,
|
||||
time_format: Optional[str] = ...,
|
||||
date_attrs: Optional[Dict[str, str]] = ...,
|
||||
time_attrs: Optional[Dict[str, str]] = ...,
|
||||
) -> None: ...
|
||||
|
||||
class SplitHiddenDateTimeWidget(SplitDateTimeWidget):
|
||||
def __init__(
|
||||
self,
|
||||
attrs: Optional[Dict[str, str]] = ...,
|
||||
date_format: None = ...,
|
||||
time_format: None = ...,
|
||||
date_attrs: Optional[Dict[str, str]] = ...,
|
||||
time_attrs: Optional[Dict[str, str]] = ...,
|
||||
) -> None: ...
|
||||
class SplitHiddenDateTimeWidget(SplitDateTimeWidget): ...
|
||||
|
||||
class SelectDateWidget(Widget):
|
||||
none_value: Any = ...
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
from typing import Any, Dict, Iterator, List, Tuple, Union
|
||||
from typing import Any, Iterator, List, Mapping, Optional, Tuple
|
||||
|
||||
from django.template.base import Template
|
||||
|
||||
class BaseEngine:
|
||||
name: Any = ...
|
||||
dirs: Any = ...
|
||||
app_dirs: Any = ...
|
||||
def __init__(self, params: Dict[str, Union[List[str], bool, str]]) -> None: ...
|
||||
name: str = ...
|
||||
dirs: List[str] = ...
|
||||
app_dirs: bool = ...
|
||||
def __init__(self, params: Mapping[str, Any]) -> None: ...
|
||||
@property
|
||||
def app_dirname(self) -> Optional[str]: ...
|
||||
def from_string(self, template_code: str) -> Template: ...
|
||||
def get_template(self, template_name: str) -> Optional[Template]: ...
|
||||
@property
|
||||
def app_dirname(self) -> None: ...
|
||||
def from_string(self, template_code: Any) -> Template: ...
|
||||
def get_template(self, template_name: Any) -> None: ...
|
||||
def template_dirs(self) -> Tuple[str]: ...
|
||||
def iter_template_filenames(self, template_name: str) -> Iterator[str]: ...
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
from typing import Any, Dict, Iterator, Optional, List
|
||||
|
||||
from django.template.base import Template as Template
|
||||
from django.template.exceptions import TemplateDoesNotExist
|
||||
from typing import Any, Dict, Iterator, Optional
|
||||
|
||||
from django.template.engine import Engine
|
||||
from django.template.exceptions import TemplateDoesNotExist
|
||||
|
||||
from .base import BaseEngine
|
||||
|
||||
class DjangoTemplates(BaseEngine):
|
||||
app_dirs: bool
|
||||
dirs: List[str]
|
||||
name: str
|
||||
app_dirname: str = ...
|
||||
engine: Engine = ...
|
||||
def __init__(self, params: Dict[str, Any]) -> None: ...
|
||||
def from_string(self, template_code: str) -> Template: ...
|
||||
def get_template(self, template_name: str) -> Template: ...
|
||||
def get_templatetag_libraries(self, custom_libraries: Dict[str, str]) -> Dict[str, str]: ...
|
||||
|
||||
def copy_exception(exc: TemplateDoesNotExist, backend: Optional[DjangoTemplates] = ...) -> TemplateDoesNotExist: ...
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
import string
|
||||
from typing import Any, Dict, List, Optional, Union, Tuple
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
|
||||
from django.http.request import HttpRequest
|
||||
|
||||
from .base import BaseEngine
|
||||
|
||||
class TemplateStrings(BaseEngine):
|
||||
app_dirs: bool
|
||||
dirs: List[Any]
|
||||
name: str
|
||||
template_dirs: Tuple[str]
|
||||
app_dirname: str = ...
|
||||
def __init__(self, params: Dict[str, Union[Dict[Any, Any], List[Any], bool, str]]) -> None: ...
|
||||
def from_string(self, template_code: str) -> Template: ...
|
||||
def get_template(self, template_name: str) -> Template: ...
|
||||
|
||||
class Template(string.Template):
|
||||
template: str
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
from typing import Callable, Dict, List, Optional, Tuple, Any
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
|
||||
from django.template.base import Template as Template
|
||||
from django.template.exceptions import TemplateSyntaxError
|
||||
|
||||
from .base import BaseEngine
|
||||
|
||||
class Jinja2(BaseEngine):
|
||||
app_dirs: bool
|
||||
dirs: List[str]
|
||||
name: str
|
||||
template_context_processors: List[Callable]
|
||||
template_dirs: Tuple[str]
|
||||
app_dirname: str = ...
|
||||
context_processors: List[str] = ...
|
||||
def __init__(self, params: Dict[str, Any]) -> None: ...
|
||||
def from_string(self, template_code: str) -> Template: ...
|
||||
def get_template(self, template_name: str) -> Template: ...
|
||||
@property
|
||||
def template_context_processors(self) -> List[Callable]: ...
|
||||
|
||||
class Origin:
|
||||
name: str = ...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from enum import Enum
|
||||
from typing import Any, Callable, Dict, Iterator, List, Mapping, Optional, Tuple, Type, Union
|
||||
from typing import Any, Callable, Dict, Iterator, List, Mapping, Optional, Sequence, Tuple, Type, Union
|
||||
|
||||
from django.http.request import HttpRequest
|
||||
from django.template.context import Context as Context
|
||||
@@ -126,12 +126,12 @@ filter_re: Any
|
||||
|
||||
class FilterExpression:
|
||||
token: str = ...
|
||||
filters: List[Tuple[Callable, List[Tuple[bool, Union[Variable, SafeText]]]]] = ...
|
||||
var: Union[Variable, SafeText] = ...
|
||||
filters: List[Any] = ...
|
||||
var: Any = ...
|
||||
def __init__(self, token: str, parser: Parser) -> None: ...
|
||||
def resolve(self, context: Union[Dict[str, Dict[str, str]], Context], ignore_failures: bool = ...) -> Any: ...
|
||||
def resolve(self, context: Mapping[str, Any], ignore_failures: bool = ...) -> Any: ...
|
||||
@staticmethod
|
||||
def args_check(name: str, func: Callable, provided: List[Tuple[bool, Union[Variable, SafeText]]]) -> bool: ...
|
||||
def args_check(name: str, func: Callable, provided: List[Tuple[bool, Any]]) -> bool: ...
|
||||
|
||||
class Variable:
|
||||
var: Union[Dict[Any, Any], str] = ...
|
||||
@@ -152,27 +152,21 @@ class Node:
|
||||
def __iter__(self) -> None: ...
|
||||
def get_nodes_by_type(self, nodetype: Type[Node]) -> List[Node]: ...
|
||||
|
||||
class NodeList(list):
|
||||
class NodeList(List[Node]):
|
||||
contains_nontext: bool = ...
|
||||
def render(self, context: Context) -> SafeText: ...
|
||||
def get_nodes_by_type(self, nodetype: Type[Node]) -> List[Node]: ...
|
||||
|
||||
class TextNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
s: str = ...
|
||||
def __init__(self, s: str) -> None: ...
|
||||
def render(self, context: Context) -> str: ...
|
||||
|
||||
def render_value_in_context(value: Any, context: Context) -> str: ...
|
||||
|
||||
class VariableNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
filter_expression: FilterExpression = ...
|
||||
def __init__(self, filter_expression: FilterExpression) -> None: ...
|
||||
def render(self, context: Context) -> str: ...
|
||||
|
||||
kwarg_re: Any
|
||||
|
||||
def token_kwargs(bits: List[str], parser: Parser, support_legacy: bool = ...) -> Dict[str, FilterExpression]: ...
|
||||
def token_kwargs(bits: Sequence[str], parser: Parser, support_legacy: bool = ...) -> Dict[str, FilterExpression]: ...
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from django.template import Engine
|
||||
|
||||
from .filesystem import Loader as FilesystemLoader
|
||||
|
||||
class Loader(FilesystemLoader):
|
||||
dirs: None
|
||||
engine: Engine
|
||||
def get_dirs(self) -> Tuple: ...
|
||||
class Loader(FilesystemLoader): ...
|
||||
|
||||
@@ -4,9 +4,9 @@ from django.template.base import Origin, Template
|
||||
from django.template.engine import Engine
|
||||
|
||||
class Loader:
|
||||
engine: Any = ...
|
||||
engine: Engine = ...
|
||||
get_template_cache: Dict[str, Any] = ...
|
||||
def __init__(self, engine: Engine) -> None: ...
|
||||
def get_template(self, template_name: str, skip: Optional[List[Origin]] = ...) -> Template: ...
|
||||
def get_template_sources(self, template_name: Any) -> None: ...
|
||||
def get_template_sources(self, template_name: str) -> None: ...
|
||||
def reset(self) -> None: ...
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
from typing import Any, Dict, List, Optional, Sequence
|
||||
|
||||
from django.template.base import Origin, Template
|
||||
from django.template.base import Origin
|
||||
from django.template.engine import Engine
|
||||
|
||||
from .base import Loader as BaseLoader
|
||||
|
||||
class Loader(BaseLoader):
|
||||
engine: Engine
|
||||
template_cache: Dict[Any, Any] = ...
|
||||
get_template_cache: Dict[str, django.template.exceptions.TemplateDoesNotExist] = ...
|
||||
loaders: List[django.template.loaders.base.Loader] = ...
|
||||
def __init__(self, engine: Engine, loaders: Union[List[Tuple[str, Dict[str, str]]], List[str]]) -> None: ...
|
||||
template_cache: Dict[str, Any] = ...
|
||||
loaders: List[BaseLoader] = ...
|
||||
def __init__(self, engine: Engine, loaders: Sequence[Any]) -> None: ...
|
||||
def get_contents(self, origin: Origin) -> str: ...
|
||||
def get_template(self, template_name: str, skip: Optional[List[Origin]] = ...) -> Template: ...
|
||||
def get_template_sources(self, template_name: str) -> None: ...
|
||||
def cache_key(self, template_name: str, skip: Optional[List[Origin]] = ...) -> str: ...
|
||||
def generate_hash(self, values: List[str]) -> str: ...
|
||||
def reset(self) -> None: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Iterator, List, Optional, Union
|
||||
from typing import Any, List, Optional, Union
|
||||
|
||||
from django.template.base import Origin
|
||||
from django.template.engine import Engine
|
||||
@@ -6,9 +6,7 @@ from django.template.engine import Engine
|
||||
from .base import Loader as BaseLoader
|
||||
|
||||
class Loader(BaseLoader):
|
||||
engine: Engine
|
||||
dirs: Optional[List[str]] = ...
|
||||
def __init__(self, engine: Engine, dirs: Optional[List[str]] = ...) -> None: ...
|
||||
def get_dirs(self) -> Union[List[bytes], List[str]]: ...
|
||||
def get_contents(self, origin: Origin) -> Any: ...
|
||||
def get_template_sources(self, template_name: Union[bytes, str]) -> Iterator[Origin]: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Dict, Iterator
|
||||
from typing import Dict
|
||||
|
||||
from django.template.base import Origin
|
||||
from django.template.engine import Engine
|
||||
@@ -6,8 +6,6 @@ from django.template.engine import Engine
|
||||
from .base import Loader as BaseLoader
|
||||
|
||||
class Loader(BaseLoader):
|
||||
engine: Engine
|
||||
templates_dict: Dict[str, str] = ...
|
||||
def __init__(self, engine: Engine, templates_dict: Dict[str, str]) -> None: ...
|
||||
def get_contents(self, origin: Origin) -> str: ...
|
||||
def get_template_sources(self, template_name: str) -> Iterator[Origin]: ...
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
from typing import Any, List, Optional
|
||||
|
||||
from django.template import Node
|
||||
from django.template.base import FilterExpression, NodeList, Parser, Token
|
||||
from django.template.context import Context
|
||||
from django.utils.safestring import SafeText
|
||||
|
||||
from django.template import Node
|
||||
|
||||
register: Any
|
||||
|
||||
class CacheNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
nodelist: NodeList = ...
|
||||
expire_time_var: FilterExpression = ...
|
||||
fragment_name: str = ...
|
||||
@@ -23,6 +20,5 @@ class CacheNode(Node):
|
||||
vary_on: List[FilterExpression],
|
||||
cache_name: Optional[FilterExpression],
|
||||
) -> None: ...
|
||||
def render(self, context: Context) -> SafeText: ...
|
||||
|
||||
def do_cache(parser: Parser, token: Token) -> CacheNode: ...
|
||||
|
||||
@@ -1,53 +1,35 @@
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from django.template import Node
|
||||
from django.template.base import FilterExpression, NodeList, Parser, Token
|
||||
from django.template.context import Context, RequestContext
|
||||
from django.utils.safestring import SafeText
|
||||
|
||||
from django.template import Node
|
||||
|
||||
register: Any
|
||||
|
||||
class GetAvailableLanguagesNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
variable: str = ...
|
||||
def __init__(self, variable: str) -> None: ...
|
||||
def render(self, context: Context) -> str: ...
|
||||
|
||||
class GetLanguageInfoNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
lang_code: FilterExpression = ...
|
||||
variable: str = ...
|
||||
def __init__(self, lang_code: FilterExpression, variable: str) -> None: ...
|
||||
def render(self, context: Context) -> str: ...
|
||||
|
||||
class GetLanguageInfoListNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
languages: FilterExpression = ...
|
||||
variable: str = ...
|
||||
def __init__(self, languages: FilterExpression, variable: str) -> None: ...
|
||||
def get_language_info(self, language: Any): ...
|
||||
def render(self, context: Context) -> str: ...
|
||||
|
||||
class GetCurrentLanguageNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
variable: str = ...
|
||||
def __init__(self, variable: str) -> None: ...
|
||||
def render(self, context: RequestContext) -> str: ...
|
||||
|
||||
class GetCurrentLanguageBidiNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
variable: str = ...
|
||||
def __init__(self, variable: str) -> None: ...
|
||||
def render(self, context: RequestContext) -> str: ...
|
||||
|
||||
class TranslateNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
noop: bool = ...
|
||||
asvar: Optional[str] = ...
|
||||
message_context: Optional[FilterExpression] = ...
|
||||
@@ -59,11 +41,8 @@ class TranslateNode(Node):
|
||||
asvar: Optional[str] = ...,
|
||||
message_context: Optional[FilterExpression] = ...,
|
||||
) -> None: ...
|
||||
def render(self, context: Context) -> str: ...
|
||||
|
||||
class BlockTranslateNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
extra_context: Dict[str, FilterExpression] = ...
|
||||
singular: List[Token] = ...
|
||||
plural: List[Token] = ...
|
||||
@@ -84,15 +63,11 @@ class BlockTranslateNode(Node):
|
||||
asvar: Optional[str] = ...,
|
||||
) -> None: ...
|
||||
def render_token_list(self, tokens: List[Token]) -> Tuple[str, List[str]]: ...
|
||||
def render(self, context: Context, nested: bool = ...) -> str: ...
|
||||
|
||||
class LanguageNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
nodelist: NodeList = ...
|
||||
language: FilterExpression = ...
|
||||
def __init__(self, nodelist: NodeList, language: FilterExpression) -> None: ...
|
||||
def render(self, context: Context) -> SafeText: ...
|
||||
|
||||
def do_get_available_languages(parser: Parser, token: Token) -> GetAvailableLanguagesNode: ...
|
||||
def do_get_language_info(parser: Parser, token: Token) -> GetLanguageInfoNode: ...
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
from datetime import date
|
||||
from typing import Any, List, Optional, Union
|
||||
from typing import Any, List
|
||||
|
||||
from django.template.base import Parser, Token
|
||||
|
||||
from django.template import Node
|
||||
from django.template.base import NodeList, Parser, Token
|
||||
from django.template.context import Context
|
||||
from django.utils.safestring import SafeText
|
||||
|
||||
register: Any
|
||||
|
||||
def localize(value: Union[date, float]) -> str: ...
|
||||
def unlocalize(value: Union[date, float]) -> str: ...
|
||||
def localize(value: Any) -> str: ...
|
||||
def unlocalize(value: Any) -> str: ...
|
||||
|
||||
class LocalizeNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
nodelist: Union[List[Any], NodeList] = ...
|
||||
nodelist: List[Node] = ...
|
||||
use_l10n: bool = ...
|
||||
def __init__(self, nodelist: Union[List[Any], NodeList], use_l10n: bool) -> None: ...
|
||||
def render(self, context: Context) -> SafeText: ...
|
||||
def __init__(self, nodelist: List[Node], use_l10n: bool) -> None: ...
|
||||
|
||||
def localize_tag(parser: Parser, token: Token) -> LocalizeNode: ...
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from django import template
|
||||
from django.template.base import FilterExpression, Parser, Token
|
||||
from django.template.context import Context
|
||||
|
||||
from django import template
|
||||
|
||||
register: Any
|
||||
|
||||
class PrefixNode(template.Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
varname: Optional[str] = ...
|
||||
name: str = ...
|
||||
def __init__(self, varname: Optional[str] = ..., name: str = ...) -> None: ...
|
||||
@@ -16,19 +15,15 @@ class PrefixNode(template.Node):
|
||||
def handle_token(cls, parser: Parser, token: Token, name: str) -> PrefixNode: ...
|
||||
@classmethod
|
||||
def handle_simple(cls, name: str) -> str: ...
|
||||
def render(self, context: Context) -> str: ...
|
||||
|
||||
def get_static_prefix(parser: Parser, token: Token) -> PrefixNode: ...
|
||||
def get_media_prefix(parser: Parser, token: Token) -> PrefixNode: ...
|
||||
|
||||
class StaticNode(template.Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
path: FilterExpression = ...
|
||||
varname: Optional[str] = ...
|
||||
def __init__(self, varname: Optional[str] = ..., path: FilterExpression = ...) -> None: ...
|
||||
def url(self, context: Context) -> str: ...
|
||||
def render(self, context: Context) -> str: ...
|
||||
@classmethod
|
||||
def handle_simple(cls, path: str) -> str: ...
|
||||
@classmethod
|
||||
|
||||
@@ -1,44 +1,32 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
from django.template import Node
|
||||
from django.template.base import FilterExpression, NodeList, Parser, Token
|
||||
from django.template.context import Context
|
||||
from django.utils.safestring import SafeText
|
||||
from django.utils.timezone import FixedOffset
|
||||
|
||||
from django.template import Node
|
||||
|
||||
register: Any
|
||||
|
||||
class datetimeobject(datetime): ...
|
||||
|
||||
def localtime(value: Optional[Union[datetime, str]]) -> Union[datetimeobject, str]: ...
|
||||
def utc(value: Optional[Union[datetime, str]]) -> Union[datetimeobject, str]: ...
|
||||
def do_timezone(
|
||||
value: Optional[Union[datetime, str]], arg: Optional[Union[FixedOffset, str]]
|
||||
) -> Union[datetimeobject, str]: ...
|
||||
def localtime(value: Optional[Union[datetime, str]]) -> Any: ...
|
||||
def utc(value: Optional[Union[datetime, str]]) -> Any: ...
|
||||
def do_timezone(value: Optional[Union[datetime, str]], arg: Optional[Union[FixedOffset, str]]) -> Any: ...
|
||||
|
||||
class LocalTimeNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
nodelist: NodeList = ...
|
||||
use_tz: bool = ...
|
||||
def __init__(self, nodelist: NodeList, use_tz: bool) -> None: ...
|
||||
def render(self, context: Context) -> SafeText: ...
|
||||
|
||||
class TimezoneNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
nodelist: NodeList = ...
|
||||
tz: FilterExpression = ...
|
||||
def __init__(self, nodelist: NodeList, tz: FilterExpression) -> None: ...
|
||||
def render(self, context: Context) -> SafeText: ...
|
||||
|
||||
class GetCurrentTimezoneNode(Node):
|
||||
origin: Origin
|
||||
token: Token
|
||||
variable: str = ...
|
||||
def __init__(self, variable: str) -> None: ...
|
||||
def render(self, context: Context) -> str: ...
|
||||
|
||||
def localtime_tag(parser: Parser, token: Token) -> LocalTimeNode: ...
|
||||
def timezone_tag(parser: Parser, token: Token) -> TimezoneNode: ...
|
||||
|
||||
@@ -31,15 +31,8 @@ class Parser(HTMLParser):
|
||||
open_tags: Any = ...
|
||||
element_positions: Any = ...
|
||||
def __init__(self) -> None: ...
|
||||
def error(self, msg: str) -> Any: ...
|
||||
def format_position(self, position: None = ..., element: None = ...) -> str: ...
|
||||
def format_position(self, position: Any = ..., element: Any = ...) -> str: ...
|
||||
@property
|
||||
def current(self) -> Element: ...
|
||||
def handle_startendtag(self, tag: str, attrs: List[Tuple[str, Optional[str]]]) -> None: ...
|
||||
def handle_starttag(self, tag: str, attrs: List[Tuple[str, Optional[str]]]) -> None: ...
|
||||
def handle_endtag(self, tag: str) -> None: ...
|
||||
def handle_data(self, data: str) -> None: ...
|
||||
def handle_charref(self, name: str) -> None: ...
|
||||
def handle_entityref(self, name: str) -> None: ...
|
||||
|
||||
def parse_html(html: str) -> Element: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Iterator, List, Optional, Tuple, Union
|
||||
from typing import Any, Dict, Iterable, Sequence, Type
|
||||
|
||||
class ArchiveException(Exception): ...
|
||||
class UnrecognizedArchiveFormat(ArchiveException): ...
|
||||
@@ -14,21 +14,17 @@ class Archive:
|
||||
def close(self) -> None: ...
|
||||
|
||||
class BaseArchive:
|
||||
def split_leading_dir(self, path: str) -> Union[List[str], Tuple[str, str]]: ...
|
||||
def has_leading_dir(self, paths: Union[Iterator[Any], List[str]]) -> bool: ...
|
||||
def extract(self) -> None: ...
|
||||
def list(self) -> None: ...
|
||||
def split_leading_dir(self, path: str) -> Sequence[str]: ...
|
||||
def has_leading_dir(self, paths: Iterable[str]) -> bool: ...
|
||||
def extract(self, to_path: str) -> None: ...
|
||||
def list(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
|
||||
class TarArchive(BaseArchive):
|
||||
def __init__(self, file: str) -> None: ...
|
||||
def list(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def extract(self, to_path: str) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
|
||||
class ZipArchive(BaseArchive):
|
||||
def __init__(self, file: str) -> None: ...
|
||||
def list(self, *args: Any, **kwargs: Any) -> None: ...
|
||||
def extract(self, to_path: str) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
|
||||
extension_map: Any
|
||||
extension_map: Dict[str, Type[BaseArchive]]
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
from datetime import date as real_date
|
||||
from datetime import datetime as real_datetime
|
||||
from datetime import time as real_time
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
class date(real_date):
|
||||
def strftime(self, fmt: str) -> str: ...
|
||||
|
||||
class datetime(real_datetime):
|
||||
def strftime(self, fmt: str) -> str: ...
|
||||
@classmethod
|
||||
def combine(cls, date: Any, time: Any): ...
|
||||
def date(self): ...
|
||||
from datetime import date as real_date, datetime as real_datetime, time as real_time
|
||||
from typing import Union
|
||||
|
||||
class date(real_date): ...
|
||||
class datetime(real_datetime): ...
|
||||
class time(real_time): ...
|
||||
|
||||
def new_date(d: date) -> date: ...
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from typing import Any, Callable, Optional, Set, Tuple, Type, Union
|
||||
|
||||
from django.middleware.cache import CacheMiddleware
|
||||
from django.test.testcases import LiveServerTestCase
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
|
||||
class classonlymethod(classmethod): ...
|
||||
@@ -9,7 +7,7 @@ class classonlymethod(classmethod): ...
|
||||
def method_decorator(
|
||||
decorator: Union[Callable, Set[Callable], Tuple[Callable, Callable]], name: str = ...
|
||||
) -> Callable: ...
|
||||
def decorator_from_middleware_with_args(middleware_class: Type[CacheMiddleware]) -> Callable: ...
|
||||
def decorator_from_middleware_with_args(middleware_class: Type[MiddlewareMixin]) -> Callable: ...
|
||||
def decorator_from_middleware(middleware_class: Type[MiddlewareMixin]) -> Callable: ...
|
||||
def available_attrs(fn: Any): ...
|
||||
def make_middleware_decorator(middleware_class: Type[MiddlewareMixin]) -> Callable: ...
|
||||
@@ -17,5 +15,5 @@ def make_middleware_decorator(middleware_class: Type[MiddlewareMixin]) -> Callab
|
||||
class classproperty:
|
||||
fget: Optional[Callable] = ...
|
||||
def __init__(self, method: Optional[Callable] = ...) -> None: ...
|
||||
def __get__(self, instance: Optional[LiveServerTestCase], cls: Type[LiveServerTestCase] = ...) -> str: ...
|
||||
def __get__(self, instance: Any, cls: Optional[type] = ...) -> Any: ...
|
||||
def getter(self, method: Callable) -> classproperty: ...
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
from datetime import date, datetime
|
||||
from io import StringIO
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
|
||||
from django.http.response import HttpResponse
|
||||
from django.utils.xmlutils import SimplerXMLGenerator
|
||||
from xml.sax import ContentHandler # type: ignore
|
||||
|
||||
def rfc2822_date(date: date) -> str: ...
|
||||
def rfc3339_date(date: date) -> str: ...
|
||||
def get_tag_uri(url: str, date: Optional[date]) -> str: ...
|
||||
|
||||
class SyndicationFeed:
|
||||
feed: Any = ...
|
||||
items: Any = ...
|
||||
feed: Dict[str, Any] = ...
|
||||
items: List[Dict[str, Any]] = ...
|
||||
def __init__(
|
||||
self,
|
||||
title: str,
|
||||
@@ -50,58 +47,30 @@ class SyndicationFeed:
|
||||
) -> None: ...
|
||||
def num_items(self): ...
|
||||
def root_attributes(self) -> Dict[Any, Any]: ...
|
||||
def add_root_elements(self, handler: Any) -> None: ...
|
||||
def add_root_elements(self, handler: ContentHandler) -> None: ...
|
||||
def item_attributes(self, item: Dict[str, Any]) -> Dict[Any, Any]: ...
|
||||
def add_item_elements(self, handler: Any, item: Any) -> None: ...
|
||||
def add_item_elements(self, handler: ContentHandler, item: Dict[str, Any]) -> None: ...
|
||||
def write(self, outfile: Any, encoding: Any) -> None: ...
|
||||
def writeString(self, encoding: str) -> str: ...
|
||||
def latest_post_date(self) -> datetime: ...
|
||||
|
||||
class Enclosure:
|
||||
length: Union[int, str]
|
||||
length: Any
|
||||
mime_type: str
|
||||
url: str = ...
|
||||
def __init__(self, url: str, length: Union[int, str], mime_type: str) -> None: ...
|
||||
|
||||
class RssFeed(SyndicationFeed):
|
||||
content_type: str = ...
|
||||
def write(self, outfile: Union[StringIO, HttpResponse], encoding: str) -> None: ...
|
||||
def rss_attributes(self) -> Dict[str, str]: ...
|
||||
def write_items(self, handler: SimplerXMLGenerator) -> None: ...
|
||||
def add_root_elements(self, handler: SimplerXMLGenerator) -> None: ...
|
||||
def endChannelElement(self, handler: SimplerXMLGenerator) -> None: ...
|
||||
def write_items(self, handler: ContentHandler) -> None: ...
|
||||
def endChannelElement(self, handler: ContentHandler) -> None: ...
|
||||
|
||||
class RssUserland091Feed(RssFeed):
|
||||
feed: Dict[str, Optional[Union[List[str], str]]]
|
||||
items: List[Dict[str, Optional[Union[List[str], Tuple, datetime.datetime, str]]]]
|
||||
def add_item_elements(
|
||||
self, handler: SimplerXMLGenerator, item: Dict[str, Optional[Union[List[str], Tuple, datetime, str]]]
|
||||
) -> None: ...
|
||||
|
||||
class Rss201rev2Feed(RssFeed):
|
||||
feed: Dict[str, Optional[Union[List[str], Tuple, str]]]
|
||||
items: Union[
|
||||
List[Dict[str, Any]],
|
||||
List[Dict[str, Optional[Union[List[django.utils.feedgenerator.Enclosure], List[str], datetime.datetime, str]]]],
|
||||
]
|
||||
def add_item_elements(self, handler: SimplerXMLGenerator, item: Dict[str, Any]) -> None: ...
|
||||
class RssUserland091Feed(RssFeed): ...
|
||||
class Rss201rev2Feed(RssFeed): ...
|
||||
|
||||
class Atom1Feed(SyndicationFeed):
|
||||
feed: Dict[str, Optional[Union[List[str], Tuple, str]]]
|
||||
items: Union[
|
||||
List[Dict[str, Optional[Union[List[django.utils.feedgenerator.Enclosure], List[str], datetime.datetime, str]]]],
|
||||
List[Dict[str, Optional[Union[List[str], Tuple, datetime.datetime, str]]]],
|
||||
]
|
||||
content_type: str = ...
|
||||
ns: str = ...
|
||||
def write(self, outfile: Union[StringIO, HttpResponse], encoding: str) -> None: ...
|
||||
def root_attributes(self) -> Dict[str, str]: ...
|
||||
def add_root_elements(self, handler: SimplerXMLGenerator) -> None: ...
|
||||
def write_items(self, handler: SimplerXMLGenerator) -> None: ...
|
||||
def add_item_elements(
|
||||
self,
|
||||
handler: SimplerXMLGenerator,
|
||||
item: Dict[str, Optional[Union[List[Enclosure], List[str], Tuple, datetime, str]]],
|
||||
) -> None: ...
|
||||
def write_items(self, handler: ContentHandler) -> None: ...
|
||||
|
||||
DefaultFeed = Rss201rev2Feed
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
from tempfile import _TemporaryFileWrapper
|
||||
from typing import Any, List, Optional, Tuple, Union
|
||||
from typing import Any
|
||||
|
||||
from django.core.checks.messages import CheckMessage
|
||||
|
||||
def is_iterable(
|
||||
x: Optional[
|
||||
Union[
|
||||
List[List[Union[List[List[Union[List[List[str]], str]]], str]]],
|
||||
List[Tuple[Optional[Union[int, str]], Union[int, str]]],
|
||||
List[CheckMessage],
|
||||
List[int],
|
||||
List[str],
|
||||
Tuple[Union[Tuple[str, str], _TemporaryFileWrapper]],
|
||||
int,
|
||||
]
|
||||
]
|
||||
) -> bool: ...
|
||||
def is_iterable(x: Any) -> bool: ...
|
||||
|
||||
@@ -2,7 +2,6 @@ import logging.config
|
||||
from logging import LogRecord
|
||||
from typing import Any, Callable, Dict, Optional, Union
|
||||
|
||||
from django.core.mail.backends.locmem import EmailBackend
|
||||
from django.core.management.color import Style
|
||||
|
||||
request_logger: Any
|
||||
@@ -15,7 +14,7 @@ class AdminEmailHandler(logging.Handler):
|
||||
email_backend: Optional[str] = ...
|
||||
def __init__(self, include_html: bool = ..., email_backend: Optional[str] = ...) -> None: ...
|
||||
def send_mail(self, subject: str, message: str, *args: Any, **kwargs: Any) -> None: ...
|
||||
def connection(self) -> EmailBackend: ...
|
||||
def connection(self) -> Any: ...
|
||||
def format_subject(self, subject: str) -> str: ...
|
||||
|
||||
class CallbackFilter(logging.Filter):
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Iterator, List, Optional, Union
|
||||
from typing import Any, Iterable, Iterator, List, Optional, Union
|
||||
|
||||
from django.db.models.base import Model
|
||||
from django.utils.functional import SimpleLazyObject
|
||||
@@ -34,7 +34,7 @@ class StreamingBuffer:
|
||||
def flush(self): ...
|
||||
def close(self): ...
|
||||
|
||||
def compress_sequence(sequence: Union[List[bytes], map]) -> Iterator[bytes]: ...
|
||||
def compress_sequence(sequence: Iterable[bytes]) -> Iterator[bytes]: ...
|
||||
|
||||
smart_split_re: Any
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Stubs for django.utils.timezone (Python 3.5)
|
||||
|
||||
from typing import Any, Optional, Union
|
||||
from datetime import tzinfo as tzinfo, datetime as datetime, timedelta as timedelta
|
||||
from contextlib import ContextDecorator
|
||||
from datetime import datetime as datetime, time, timedelta as timedelta, tzinfo as tzinfo
|
||||
from typing import Optional, Union
|
||||
|
||||
_AnyTime = Union[time, datetime]
|
||||
|
||||
class UTC(tzinfo):
|
||||
def utcoffset(self, dt: Optional[datetime]) -> Optional[timedelta]: ...
|
||||
@@ -16,9 +16,9 @@ class FixedOffset(tzinfo):
|
||||
def dst(self, dt: Optional[datetime]) -> Optional[timedelta]: ...
|
||||
|
||||
class ReferenceLocalTimezone(tzinfo):
|
||||
STDOFFSET = ... # type: timedelta
|
||||
DSTOFFSET = ... # type: timedelta
|
||||
DSTDIFF = ... # type: timedelta
|
||||
STDOFFSET: timedelta = ...
|
||||
DSTOFFSET: timedelta = ...
|
||||
DSTDIFF: timedelta = ...
|
||||
def __init__(self) -> None: ...
|
||||
def utcoffset(self, dt: Optional[datetime]) -> Optional[timedelta]: ...
|
||||
def dst(self, dt: Optional[datetime]) -> Optional[timedelta]: ...
|
||||
@@ -27,7 +27,7 @@ class ReferenceLocalTimezone(tzinfo):
|
||||
class LocalTimezone(ReferenceLocalTimezone):
|
||||
def tzname(self, dt: Optional[datetime]) -> str: ...
|
||||
|
||||
utc = ... # type: UTC
|
||||
utc: UTC = ...
|
||||
|
||||
def get_fixed_timezone(offset: Union[timedelta, int]) -> tzinfo: ...
|
||||
def get_default_timezone() -> tzinfo: ...
|
||||
@@ -38,15 +38,15 @@ def activate(timezone: tzinfo) -> None: ...
|
||||
def deactivate() -> None: ...
|
||||
|
||||
class override(ContextDecorator):
|
||||
timezone = ... # type: tzinfo
|
||||
old_timezone = ... # type: tzinfo
|
||||
timezone: tzinfo = ...
|
||||
old_timezone: tzinfo = ...
|
||||
def __init__(self, timezone: tzinfo) -> None: ...
|
||||
def __enter__(self) -> None: ...
|
||||
def __exit__(self, exc_type: object, exc_value: object, traceback: object) -> None: ...
|
||||
|
||||
def localtime(value: datetime, timezone: tzinfo = None) -> datetime: ...
|
||||
def localtime(value: _AnyTime, timezone: Optional[tzinfo] = None) -> datetime: ...
|
||||
def now() -> datetime: ...
|
||||
def is_aware(value: datetime) -> bool: ...
|
||||
def is_naive(value: datetime) -> bool: ...
|
||||
def make_aware(value: datetime, timezone: tzinfo = None, is_dst: bool = None) -> datetime: ...
|
||||
def make_naive(value: datetime, timezone: tzinfo = None) -> datetime: ...
|
||||
def is_aware(value: _AnyTime) -> bool: ...
|
||||
def is_naive(value: _AnyTime) -> bool: ...
|
||||
def make_aware(value: _AnyTime, timezone: Optional[tzinfo] = None, is_dst: Optional[bool] = None) -> datetime: ...
|
||||
def make_naive(value: _AnyTime, timezone: Optional[tzinfo] = None) -> datetime: ...
|
||||
|
||||
@@ -11,7 +11,7 @@ class MultipleObjectMixin(ContextMixin):
|
||||
allow_empty: bool = ...
|
||||
queryset: Optional[QuerySet] = ...
|
||||
model: Optional[Type[Model]] = ...
|
||||
paginate_by: Optional[int] = ...
|
||||
paginate_by: int = ...
|
||||
paginate_orphans: int = ...
|
||||
context_object_name: Optional[str] = ...
|
||||
paginator_class: Type[Paginator] = ...
|
||||
|
||||
@@ -8,6 +8,7 @@ from dataclasses import dataclass
|
||||
class Config:
|
||||
django_settings_module: Optional[str] = None
|
||||
ignore_missing_settings: bool = False
|
||||
ignore_missing_model_attributes: bool = False
|
||||
|
||||
@classmethod
|
||||
def from_config_file(cls, fpath: str) -> 'Config':
|
||||
@@ -22,5 +23,9 @@ class Config:
|
||||
django_settings = django_settings.strip()
|
||||
|
||||
return Config(django_settings_module=django_settings,
|
||||
ignore_missing_settings=bool(ini_config.get('mypy_django_plugin', 'ignore_missing_settings',
|
||||
fallback=False)))
|
||||
ignore_missing_settings=bool(ini_config.get('mypy_django_plugin',
|
||||
'ignore_missing_settings',
|
||||
fallback=False)),
|
||||
ignore_missing_model_attributes=bool(ini_config.get('mypy_django_plugin',
|
||||
'ignore_missing_model_attributes',
|
||||
fallback=False)))
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
import typing
|
||||
from typing import Dict, Optional
|
||||
from collections import OrderedDict
|
||||
from typing import Dict, Optional, cast
|
||||
|
||||
from mypy.checker import TypeChecker
|
||||
from mypy.mro import calculate_mro
|
||||
from mypy.nodes import (
|
||||
AssignmentStmt, ClassDef, Expression, ImportedName, Lvalue, MypyFile, NameExpr, SymbolNode, TypeInfo,
|
||||
GDEF, MDEF, AssignmentStmt, Block, CallExpr, ClassDef, Expression, ImportedName, Lvalue, MypyFile, NameExpr,
|
||||
SymbolNode, SymbolTable, SymbolTableNode, TypeInfo, Var,
|
||||
)
|
||||
from mypy.plugin import FunctionContext, MethodContext
|
||||
from mypy.plugin import CheckerPluginInterface, FunctionContext, MethodContext
|
||||
from mypy.types import (
|
||||
AnyType, Instance, NoneTyp, Type, TypeOfAny, TypeVarType, UnionType,
|
||||
AnyType, Instance, NoneTyp, TupleType, Type, TypedDictType, TypeOfAny, TypeVarType, UnionType,
|
||||
)
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from mypy.checker import TypeChecker
|
||||
|
||||
MODEL_CLASS_FULLNAME = 'django.db.models.base.Model'
|
||||
FIELD_FULLNAME = 'django.db.models.fields.Field'
|
||||
CHAR_FIELD_FULLNAME = 'django.db.models.fields.CharField'
|
||||
@@ -163,7 +168,7 @@ def get_argument_type_by_name(ctx: typing.Union[FunctionContext, MethodContext],
|
||||
return arg_types[0]
|
||||
|
||||
|
||||
def get_setting_expr(api: TypeChecker, setting_name: str) -> Optional[Expression]:
|
||||
def get_setting_expr(api: 'TypeChecker', setting_name: str) -> Optional[Expression]:
|
||||
try:
|
||||
settings_sym = api.modules['django.conf'].names['settings']
|
||||
except KeyError:
|
||||
@@ -211,7 +216,8 @@ def extract_field_setter_type(tp: Instance) -> Optional[Type]:
|
||||
return None
|
||||
|
||||
|
||||
def extract_field_getter_type(tp: Instance) -> Optional[Type]:
|
||||
def extract_field_getter_type(tp: Type) -> Optional[Type]:
|
||||
""" Extract return type of __get__ of subclass of Field"""
|
||||
if not isinstance(tp, Instance):
|
||||
return None
|
||||
if tp.type.has_base(FIELD_FULLNAME):
|
||||
@@ -222,19 +228,26 @@ def extract_field_getter_type(tp: Instance) -> Optional[Type]:
|
||||
return None
|
||||
|
||||
|
||||
def get_django_metadata(model: TypeInfo) -> Dict[str, typing.Any]:
|
||||
return model.metadata.setdefault('django', {})
|
||||
def get_django_metadata(model_info: TypeInfo) -> Dict[str, typing.Any]:
|
||||
return model_info.metadata.setdefault('django', {})
|
||||
|
||||
|
||||
def get_related_field_primary_key_names(base_model: TypeInfo) -> typing.List[str]:
|
||||
django_metadata = get_django_metadata(base_model)
|
||||
return django_metadata.setdefault('related_field_primary_keys', [])
|
||||
return get_django_metadata(base_model).setdefault('related_field_primary_keys', [])
|
||||
|
||||
|
||||
def get_fields_metadata(model: TypeInfo) -> Dict[str, typing.Any]:
|
||||
return get_django_metadata(model).setdefault('fields', {})
|
||||
|
||||
|
||||
def get_lookups_metadata(model: TypeInfo) -> Dict[str, typing.Any]:
|
||||
return get_django_metadata(model).setdefault('lookups', {})
|
||||
|
||||
|
||||
def get_related_managers_metadata(model: TypeInfo) -> Dict[str, typing.Any]:
|
||||
return get_django_metadata(model).setdefault('related_managers', {})
|
||||
|
||||
|
||||
def extract_explicit_set_type_of_model_primary_key(model: TypeInfo) -> Optional[Type]:
|
||||
"""
|
||||
If field with primary_key=True is set on the model, extract its __set__ type.
|
||||
@@ -296,3 +309,135 @@ def get_assigned_value_for_class(type_info: TypeInfo, name: str) -> Optional[Exp
|
||||
if isinstance(lvalue, NameExpr) and lvalue.name == name:
|
||||
return rvalue
|
||||
return None
|
||||
|
||||
|
||||
def is_field_nullable(model: TypeInfo, field_name: str) -> bool:
|
||||
return get_fields_metadata(model).get(field_name, {}).get('null', False)
|
||||
|
||||
|
||||
def is_foreign_key_like(t: Type) -> bool:
|
||||
if not isinstance(t, Instance):
|
||||
return False
|
||||
return has_any_of_bases(t.type, (FOREIGN_KEY_FULLNAME, ONETOONE_FIELD_FULLNAME))
|
||||
|
||||
|
||||
def build_class_with_annotated_fields(api: 'TypeChecker', base: Type, fields: 'OrderedDict[str, Type]',
|
||||
name: str) -> Instance:
|
||||
"""Build an Instance with `name` that contains the specified `fields` as attributes and extends `base`."""
|
||||
# Credit: This code is largely copied/modified from TypeChecker.intersect_instance_callable and
|
||||
# NamedTupleAnalyzer.build_namedtuple_typeinfo
|
||||
from mypy.checker import gen_unique_name
|
||||
|
||||
cur_module = cast(MypyFile, api.scope.stack[0])
|
||||
gen_name = gen_unique_name(name, cur_module.names)
|
||||
|
||||
cdef = ClassDef(name, Block([]))
|
||||
cdef.fullname = cur_module.fullname() + '.' + gen_name
|
||||
info = TypeInfo(SymbolTable(), cdef, cur_module.fullname())
|
||||
cdef.info = info
|
||||
info.bases = [base]
|
||||
|
||||
def add_field(var: Var, is_initialized_in_class: bool = False,
|
||||
is_property: bool = False) -> None:
|
||||
var.info = info
|
||||
var.is_initialized_in_class = is_initialized_in_class
|
||||
var.is_property = is_property
|
||||
var._fullname = '%s.%s' % (info.fullname(), var.name())
|
||||
info.names[var.name()] = SymbolTableNode(MDEF, var)
|
||||
|
||||
vars = [Var(item, typ) for item, typ in fields.items()]
|
||||
for var in vars:
|
||||
add_field(var, is_property=True)
|
||||
|
||||
calculate_mro(info)
|
||||
info.calculate_metaclass_type()
|
||||
|
||||
cur_module.names[gen_name] = SymbolTableNode(GDEF, info, plugin_generated=True)
|
||||
return Instance(info, [])
|
||||
|
||||
|
||||
def make_named_tuple(api: 'TypeChecker', fields: 'OrderedDict[str, Type]', name: str) -> Type:
|
||||
if not fields:
|
||||
# No fields specified, so fallback to a subclass of NamedTuple that allows
|
||||
# __getattr__ / __setattr__ for any attribute name.
|
||||
fallback = api.named_generic_type('django._NamedTupleAnyAttr', [])
|
||||
else:
|
||||
fallback = build_class_with_annotated_fields(
|
||||
api=api,
|
||||
base=api.named_generic_type('typing.NamedTuple', []),
|
||||
fields=fields,
|
||||
name=name
|
||||
)
|
||||
return TupleType(list(fields.values()), fallback=fallback)
|
||||
|
||||
|
||||
def make_typeddict(api: CheckerPluginInterface, fields: 'OrderedDict[str, Type]',
|
||||
required_keys: typing.Set[str]) -> TypedDictType:
|
||||
object_type = api.named_generic_type('mypy_extensions._TypedDict', [])
|
||||
typed_dict_type = TypedDictType(fields, required_keys=required_keys, fallback=object_type)
|
||||
return typed_dict_type
|
||||
|
||||
|
||||
def make_tuple(api: 'TypeChecker', fields: typing.List[Type]) -> TupleType:
|
||||
implicit_any = AnyType(TypeOfAny.special_form)
|
||||
fallback = api.named_generic_type('builtins.tuple', [implicit_any])
|
||||
return TupleType(fields, fallback=fallback)
|
||||
|
||||
|
||||
def get_private_descriptor_type(type_info: TypeInfo, private_field_name: str, is_nullable: bool) -> Type:
|
||||
node = type_info.get(private_field_name).node
|
||||
if isinstance(node, Var):
|
||||
descriptor_type = node.type
|
||||
if is_nullable:
|
||||
descriptor_type = make_optional(descriptor_type)
|
||||
return descriptor_type
|
||||
return AnyType(TypeOfAny.unannotated)
|
||||
|
||||
|
||||
def iter_over_classdefs(module_file: MypyFile) -> typing.Iterator[ClassDef]:
|
||||
for defn in module_file.defs:
|
||||
if isinstance(defn, ClassDef):
|
||||
yield defn
|
||||
|
||||
|
||||
def iter_call_assignments(klass: ClassDef) -> typing.Iterator[typing.Tuple[Lvalue, CallExpr]]:
|
||||
for lvalue, rvalue in iter_over_assignments(klass):
|
||||
if isinstance(rvalue, CallExpr):
|
||||
yield lvalue, rvalue
|
||||
|
||||
|
||||
def get_related_manager_type_from_metadata(model_info: TypeInfo, related_manager_name: str,
|
||||
api: CheckerPluginInterface) -> Optional[Instance]:
|
||||
related_manager_metadata = get_related_managers_metadata(model_info)
|
||||
if not related_manager_metadata:
|
||||
return None
|
||||
|
||||
if related_manager_name not in related_manager_metadata:
|
||||
return None
|
||||
|
||||
manager_class_name = related_manager_metadata[related_manager_name]['manager']
|
||||
of = related_manager_metadata[related_manager_name]['of']
|
||||
of_types = []
|
||||
for of_type_name in of:
|
||||
if of_type_name == 'any':
|
||||
of_types.append(AnyType(TypeOfAny.implementation_artifact))
|
||||
else:
|
||||
try:
|
||||
of_type = api.named_generic_type(of_type_name, [])
|
||||
except AssertionError:
|
||||
# Internal error: attempted lookup of unknown name
|
||||
of_type = AnyType(TypeOfAny.implementation_artifact)
|
||||
|
||||
of_types.append(of_type)
|
||||
|
||||
return api.named_generic_type(manager_class_name, of_types)
|
||||
|
||||
|
||||
def get_primary_key_field_name(model_info: TypeInfo) -> Optional[str]:
|
||||
for base in model_info.mro:
|
||||
fields = get_fields_metadata(base)
|
||||
for field_name, field_props in fields.items():
|
||||
is_primary_key = field_props.get('primary_key', False)
|
||||
if is_primary_key:
|
||||
return field_name
|
||||
return None
|
||||
|
||||
159
mypy_django_plugin/lookups.py
Normal file
159
mypy_django_plugin/lookups.py
Normal file
@@ -0,0 +1,159 @@
|
||||
from typing import List, Union
|
||||
|
||||
import dataclasses
|
||||
from mypy.nodes import TypeInfo
|
||||
from mypy.plugin import CheckerPluginInterface
|
||||
from mypy.types import Instance, Type
|
||||
|
||||
from mypy_django_plugin import helpers
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class RelatedModelNode:
|
||||
typ: Instance
|
||||
is_nullable: bool
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class FieldNode:
|
||||
typ: Type
|
||||
|
||||
|
||||
LookupNode = Union[RelatedModelNode, FieldNode]
|
||||
|
||||
|
||||
class LookupException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def resolve_lookup(api: CheckerPluginInterface, model_type_info: TypeInfo, lookup: str) -> List[LookupNode]:
|
||||
"""Resolve a lookup str to a list of LookupNodes.
|
||||
|
||||
Each node represents a part of the lookup (separated by "__"), in order.
|
||||
Each node is the Model or Field that was resolved.
|
||||
|
||||
Raises LookupException if there were any issues resolving the lookup.
|
||||
"""
|
||||
lookup_parts = lookup.split("__")
|
||||
|
||||
nodes = []
|
||||
while lookup_parts:
|
||||
lookup_part = lookup_parts.pop(0)
|
||||
|
||||
if not nodes:
|
||||
current_node = None
|
||||
else:
|
||||
current_node = nodes[-1]
|
||||
|
||||
if current_node is None:
|
||||
new_node = resolve_model_lookup(api, model_type_info, lookup_part)
|
||||
elif isinstance(current_node, RelatedModelNode):
|
||||
new_node = resolve_model_lookup(api, current_node.typ.type, lookup_part)
|
||||
elif isinstance(current_node, FieldNode):
|
||||
raise LookupException(f"Field lookups not yet supported for lookup {lookup}")
|
||||
else:
|
||||
raise LookupException(f"Unsupported node type: {type(current_node)}")
|
||||
nodes.append(new_node)
|
||||
return nodes
|
||||
|
||||
|
||||
def resolve_model_pk_lookup(api: CheckerPluginInterface, model_type_info: TypeInfo) -> LookupNode:
|
||||
# Primary keys are special-cased
|
||||
primary_key_type = helpers.extract_primary_key_type_for_get(model_type_info)
|
||||
if primary_key_type:
|
||||
return FieldNode(primary_key_type)
|
||||
else:
|
||||
# No PK, use the get type for AutoField as PK type.
|
||||
autofield_info = api.lookup_typeinfo('django.db.models.fields.AutoField')
|
||||
pk_type = helpers.get_private_descriptor_type(autofield_info, '_pyi_private_get_type',
|
||||
is_nullable=False)
|
||||
return FieldNode(pk_type)
|
||||
|
||||
|
||||
def resolve_model_lookup(api: CheckerPluginInterface, model_type_info: TypeInfo,
|
||||
lookup: str) -> LookupNode:
|
||||
"""Resolve a lookup on the given model."""
|
||||
if lookup == 'pk':
|
||||
return resolve_model_pk_lookup(api, model_type_info)
|
||||
|
||||
field_name = get_actual_field_name_for_lookup_field(lookup, model_type_info)
|
||||
|
||||
field_node = model_type_info.get(field_name)
|
||||
if not field_node:
|
||||
raise LookupException(
|
||||
f'When resolving lookup "{lookup}", field "{field_name}" was not found in model {model_type_info.name()}')
|
||||
|
||||
if field_name.endswith('_id'):
|
||||
field_name_without_id = field_name.rstrip('_id')
|
||||
foreign_key_field = model_type_info.get(field_name_without_id)
|
||||
if foreign_key_field is not None and helpers.is_foreign_key_like(foreign_key_field.type):
|
||||
# Hack: If field ends with '_id' and there is a model field without the '_id' suffix, then use that field.
|
||||
field_node = foreign_key_field
|
||||
field_name = field_name_without_id
|
||||
|
||||
field_node_type = field_node.type
|
||||
if field_node_type is None or not isinstance(field_node_type, Instance):
|
||||
raise LookupException(
|
||||
f'When resolving lookup "{lookup}", could not determine type for {model_type_info.name()}.{field_name}')
|
||||
|
||||
if field_node_type.type.fullname() == 'builtins.object':
|
||||
# could be related manager
|
||||
related_manager_type = helpers.get_related_manager_type_from_metadata(model_type_info, field_name, api)
|
||||
if related_manager_type:
|
||||
model_arg = related_manager_type.args[0]
|
||||
if not isinstance(model_arg, Instance):
|
||||
raise LookupException(
|
||||
f'When resolving lookup "{lookup}", could not determine type '
|
||||
f'for {model_type_info.name()}.{field_name}')
|
||||
|
||||
return RelatedModelNode(typ=model_arg, is_nullable=False)
|
||||
|
||||
if helpers.is_foreign_key_like(field_node_type):
|
||||
field_type = helpers.extract_field_getter_type(field_node_type)
|
||||
is_nullable = helpers.is_optional(field_type)
|
||||
if is_nullable:
|
||||
# type is always non-optional
|
||||
field_type = helpers.make_required(field_type)
|
||||
|
||||
if isinstance(field_type, Instance):
|
||||
return RelatedModelNode(typ=field_type, is_nullable=is_nullable)
|
||||
else:
|
||||
raise LookupException(f"Not an instance for field {field_type} lookup {lookup}")
|
||||
|
||||
field_type = helpers.extract_field_getter_type(field_node_type)
|
||||
if field_type:
|
||||
return FieldNode(typ=field_type)
|
||||
|
||||
# Not a Field
|
||||
if field_name == 'id':
|
||||
# If no 'id' field was found, use an int
|
||||
return FieldNode(api.named_generic_type('builtins.int', []))
|
||||
|
||||
raise LookupException(
|
||||
f'When resolving lookup {lookup!r}, could not determine type for {model_type_info.name()}.{field_name}')
|
||||
|
||||
|
||||
def get_actual_field_name_for_lookup_field(lookup: str, model_type_info: TypeInfo) -> str:
|
||||
"""Attempt to find out the real field name if this lookup is a related_query_name (for reverse relations).
|
||||
|
||||
If it's not, return the original lookup.
|
||||
"""
|
||||
lookups_metadata = helpers.get_lookups_metadata(model_type_info)
|
||||
lookup_metadata = lookups_metadata.get(lookup)
|
||||
if lookup_metadata is None:
|
||||
# If not found on current model, look in all bases for their lookup metadata
|
||||
for base in model_type_info.mro:
|
||||
lookups_metadata = helpers.get_lookups_metadata(base)
|
||||
lookup_metadata = lookups_metadata.get(lookup)
|
||||
if lookup_metadata:
|
||||
break
|
||||
if not lookup_metadata:
|
||||
lookup_metadata = {}
|
||||
related_name = lookup_metadata.get('related_query_name_target', None)
|
||||
if related_name:
|
||||
# If the lookup is a related lookup, then look at the field specified by related_name.
|
||||
# This is to support if related_query_name is set and differs from.
|
||||
field_name = related_name
|
||||
else:
|
||||
field_name = lookup
|
||||
return field_name
|
||||
@@ -1,34 +1,37 @@
|
||||
from functools import partial
|
||||
|
||||
import os
|
||||
from typing import Callable, Dict, Optional, Union, cast
|
||||
from functools import partial
|
||||
from typing import Callable, Dict, List, Optional, Tuple, cast
|
||||
|
||||
from mypy.checker import TypeChecker
|
||||
from mypy.nodes import MemberExpr, NameExpr, TypeInfo
|
||||
from mypy.nodes import MypyFile, NameExpr, TypeInfo
|
||||
from mypy.options import Options
|
||||
from mypy.plugin import (
|
||||
AttributeContext, ClassDefContext, FunctionContext, MethodContext, Plugin,
|
||||
AnalyzeTypeContext)
|
||||
from mypy.types import (
|
||||
AnyType, CallableType, Instance, NoneTyp, Type, TypeOfAny, TypeType, UnionType,
|
||||
AnalyzeTypeContext, AttributeContext, ClassDefContext, FunctionContext, MethodContext, Plugin,
|
||||
)
|
||||
from mypy.types import AnyType, Instance, Type, TypeOfAny
|
||||
|
||||
from mypy_django_plugin import helpers, monkeypatch
|
||||
from mypy_django_plugin import helpers
|
||||
from mypy_django_plugin.config import Config
|
||||
from mypy_django_plugin.transformers import fields, init_create
|
||||
from mypy_django_plugin.transformers.forms import (
|
||||
make_meta_nested_class_inherit_from_any,
|
||||
extract_proper_type_for_get_form, extract_proper_type_for_get_form_class, make_meta_nested_class_inherit_from_any,
|
||||
)
|
||||
from mypy_django_plugin.transformers.migrations import (
|
||||
determine_model_cls_from_string_for_migrations, get_string_value_from_expr,
|
||||
determine_model_cls_from_string_for_migrations,
|
||||
)
|
||||
from mypy_django_plugin.transformers.models import process_model_class
|
||||
from mypy_django_plugin.transformers.queryset import (
|
||||
extract_proper_type_for_queryset_values, extract_proper_type_queryset_values_list,
|
||||
set_first_generic_param_as_default_for_second,
|
||||
)
|
||||
from mypy_django_plugin.transformers.related import (
|
||||
determine_type_of_related_manager, extract_and_return_primary_key_of_bound_related_field_parameter,
|
||||
)
|
||||
from mypy_django_plugin.transformers.settings import (
|
||||
AddSettingValuesToDjangoConfObject, get_settings_metadata,
|
||||
get_type_of_setting, return_user_model_hook,
|
||||
)
|
||||
|
||||
|
||||
def transform_model_class(ctx: ClassDefContext) -> None:
|
||||
def transform_model_class(ctx: ClassDefContext, ignore_missing_model_attributes: bool) -> None:
|
||||
try:
|
||||
sym = ctx.api.lookup_fully_qualified(helpers.MODEL_CLASS_FULLNAME)
|
||||
except KeyError:
|
||||
@@ -36,25 +39,28 @@ def transform_model_class(ctx: ClassDefContext) -> None:
|
||||
pass
|
||||
else:
|
||||
if sym is not None and isinstance(sym.node, TypeInfo):
|
||||
sym.node.metadata['django']['model_bases'][ctx.cls.fullname] = 1
|
||||
process_model_class(ctx)
|
||||
helpers.get_django_metadata(sym.node)['model_bases'][ctx.cls.fullname] = 1
|
||||
|
||||
process_model_class(ctx, ignore_missing_model_attributes)
|
||||
|
||||
|
||||
def transform_manager_class(ctx: ClassDefContext) -> None:
|
||||
sym = ctx.api.lookup_fully_qualified_or_none(helpers.MANAGER_CLASS_FULLNAME)
|
||||
if sym is not None and isinstance(sym.node, TypeInfo):
|
||||
sym.node.metadata['django']['manager_bases'][ctx.cls.fullname] = 1
|
||||
helpers.get_django_metadata(sym.node)['manager_bases'][ctx.cls.fullname] = 1
|
||||
|
||||
|
||||
def transform_form_class(ctx: ClassDefContext) -> None:
|
||||
sym = ctx.api.lookup_fully_qualified_or_none(helpers.BASEFORM_CLASS_FULLNAME)
|
||||
if sym is not None and isinstance(sym.node, TypeInfo):
|
||||
sym.node.metadata['django']['baseform_bases'][ctx.cls.fullname] = 1
|
||||
helpers.get_django_metadata(sym.node)['baseform_bases'][ctx.cls.fullname] = 1
|
||||
|
||||
make_meta_nested_class_inherit_from_any(ctx)
|
||||
|
||||
|
||||
def determine_proper_manager_type(ctx: FunctionContext) -> Type:
|
||||
from mypy.checker import TypeChecker
|
||||
|
||||
api = cast(TypeChecker, ctx.api)
|
||||
ret = ctx.default_return_type
|
||||
if not api.tscope.classes:
|
||||
@@ -82,110 +88,31 @@ def determine_proper_manager_type(ctx: FunctionContext) -> Type:
|
||||
return ret
|
||||
|
||||
|
||||
def set_first_generic_param_as_default_for_second(fullname: str, ctx: AnalyzeTypeContext) -> Type:
|
||||
if not ctx.type.args:
|
||||
return ctx.api.named_type(fullname, [AnyType(TypeOfAny.explicit),
|
||||
AnyType(TypeOfAny.explicit)])
|
||||
args = ctx.type.args
|
||||
if len(args) == 1:
|
||||
args = [args[0], args[0]]
|
||||
def return_type_for_id_field(ctx: AttributeContext) -> Type:
|
||||
if not isinstance(ctx.type, Instance):
|
||||
return AnyType(TypeOfAny.from_error)
|
||||
|
||||
analyzed_args = [ctx.api.analyze_type(arg) for arg in args]
|
||||
return ctx.api.named_type(fullname, analyzed_args)
|
||||
|
||||
|
||||
def return_user_model_hook(ctx: FunctionContext) -> Type:
|
||||
api = cast(TypeChecker, ctx.api)
|
||||
setting_expr = helpers.get_setting_expr(api, 'AUTH_USER_MODEL')
|
||||
if setting_expr is None:
|
||||
return ctx.default_return_type
|
||||
|
||||
model_path = get_string_value_from_expr(setting_expr)
|
||||
if model_path is None:
|
||||
return ctx.default_return_type
|
||||
|
||||
app_label, _, model_class_name = model_path.rpartition('.')
|
||||
if app_label is None:
|
||||
return ctx.default_return_type
|
||||
|
||||
model_fullname = helpers.get_model_fullname(app_label, model_class_name,
|
||||
all_modules=api.modules)
|
||||
if model_fullname is None:
|
||||
api.fail(f'"{app_label}.{model_class_name}" model class is not imported so far. Try to import it '
|
||||
f'(under if TYPE_CHECKING) at the beginning of the current file',
|
||||
context=ctx.context)
|
||||
return ctx.default_return_type
|
||||
|
||||
model_info = helpers.lookup_fully_qualified_generic(model_fullname,
|
||||
all_modules=api.modules)
|
||||
if model_info is None or not isinstance(model_info, TypeInfo):
|
||||
return ctx.default_return_type
|
||||
return TypeType(Instance(model_info, []))
|
||||
|
||||
|
||||
def _extract_referred_to_type_info(typ: Union[UnionType, Instance]) -> Optional[TypeInfo]:
|
||||
if isinstance(typ, Instance):
|
||||
return typ.type
|
||||
else:
|
||||
# should be Union[TYPE, None]
|
||||
typ = helpers.make_required(typ)
|
||||
if isinstance(typ, Instance):
|
||||
return typ.type
|
||||
return None
|
||||
|
||||
|
||||
def extract_and_return_primary_key_of_bound_related_field_parameter(ctx: AttributeContext) -> Type:
|
||||
if not isinstance(ctx.default_attr_type, Instance) or not (ctx.default_attr_type.type.fullname() == 'builtins.int'):
|
||||
return ctx.default_attr_type
|
||||
|
||||
if not isinstance(ctx.type, Instance) or not ctx.type.type.has_base(helpers.MODEL_CLASS_FULLNAME):
|
||||
return ctx.default_attr_type
|
||||
|
||||
field_name = ctx.context.name.split('_')[0]
|
||||
sym = ctx.type.type.get(field_name)
|
||||
if sym and isinstance(sym.type, Instance) and len(sym.type.args) > 0:
|
||||
referred_to = sym.type.args[1]
|
||||
if isinstance(referred_to, AnyType):
|
||||
return AnyType(TypeOfAny.implementation_artifact)
|
||||
|
||||
model_type = _extract_referred_to_type_info(referred_to)
|
||||
if model_type is None:
|
||||
return AnyType(TypeOfAny.implementation_artifact)
|
||||
|
||||
primary_key_type = helpers.extract_primary_key_type_for_get(model_type)
|
||||
if primary_key_type:
|
||||
return primary_key_type
|
||||
|
||||
is_nullable = helpers.get_fields_metadata(ctx.type.type).get(field_name, {}).get('null', False)
|
||||
if is_nullable:
|
||||
return helpers.make_optional(ctx.default_attr_type)
|
||||
|
||||
return ctx.default_attr_type
|
||||
|
||||
|
||||
def return_integer_type_for_id_for_non_defined_primary_key_in_models(ctx: AttributeContext) -> Type:
|
||||
if isinstance(ctx.type, Instance) and ctx.type.type.has_base(helpers.MODEL_CLASS_FULLNAME):
|
||||
model_info = ctx.type.type # type: TypeInfo
|
||||
primary_key_field_name = helpers.get_primary_key_field_name(model_info)
|
||||
if not primary_key_field_name:
|
||||
# no field with primary_key=True, just return id as int
|
||||
return ctx.api.named_generic_type('builtins.int', [])
|
||||
return ctx.default_attr_type
|
||||
|
||||
if primary_key_field_name != 'id':
|
||||
# there's field with primary_key=True, but it's name is not 'id', fail
|
||||
ctx.api.fail("Default primary key 'id' is not defined", ctx.context)
|
||||
return AnyType(TypeOfAny.from_error)
|
||||
|
||||
class ExtractSettingType:
|
||||
def __init__(self, module_fullname: str):
|
||||
self.module_fullname = module_fullname
|
||||
primary_key_sym = model_info.get(primary_key_field_name)
|
||||
if primary_key_sym and isinstance(primary_key_sym.type, Instance):
|
||||
pass
|
||||
|
||||
def __call__(self, ctx: AttributeContext) -> Type:
|
||||
api = cast(TypeChecker, ctx.api)
|
||||
original_module = api.modules.get(self.module_fullname)
|
||||
if original_module is None:
|
||||
return ctx.default_attr_type
|
||||
# try to parse field type out of primary key field
|
||||
field_type = helpers.extract_field_getter_type(primary_key_sym.type)
|
||||
if field_type:
|
||||
return field_type
|
||||
|
||||
definition = ctx.context
|
||||
if isinstance(definition, MemberExpr):
|
||||
sym = original_module.names.get(definition.name)
|
||||
if sym and sym.type:
|
||||
return sym.type
|
||||
|
||||
return ctx.default_attr_type
|
||||
return primary_key_sym.type
|
||||
|
||||
|
||||
def transform_form_view(ctx: ClassDefContext) -> None:
|
||||
@@ -194,48 +121,10 @@ def transform_form_view(ctx: ClassDefContext) -> None:
|
||||
helpers.get_django_metadata(ctx.cls.info)['form_class'] = form_class_value.fullname
|
||||
|
||||
|
||||
def extract_proper_type_for_get_form_class(ctx: MethodContext) -> Type:
|
||||
object_type = ctx.type
|
||||
if not isinstance(object_type, Instance):
|
||||
return ctx.default_return_type
|
||||
|
||||
form_class_fullname = helpers.get_django_metadata(object_type.type).get('form_class', None)
|
||||
if not form_class_fullname:
|
||||
return ctx.default_return_type
|
||||
|
||||
return TypeType(ctx.api.named_generic_type(form_class_fullname, []))
|
||||
|
||||
|
||||
def extract_proper_type_for_get_form(ctx: MethodContext) -> Type:
|
||||
object_type = ctx.type
|
||||
if not isinstance(object_type, Instance):
|
||||
return ctx.default_return_type
|
||||
|
||||
form_class_type = helpers.get_argument_type_by_name(ctx, 'form_class')
|
||||
if form_class_type is None or isinstance(form_class_type, NoneTyp):
|
||||
# extract from specified form_class in metadata
|
||||
form_class_fullname = helpers.get_django_metadata(object_type.type).get('form_class', None)
|
||||
if not form_class_fullname:
|
||||
return ctx.default_return_type
|
||||
|
||||
return ctx.api.named_generic_type(form_class_fullname, [])
|
||||
|
||||
if isinstance(form_class_type, TypeType) and isinstance(form_class_type.item, Instance):
|
||||
return form_class_type.item
|
||||
|
||||
if isinstance(form_class_type, CallableType) and isinstance(form_class_type.ret_type, Instance):
|
||||
return form_class_type.ret_type
|
||||
|
||||
return ctx.default_return_type
|
||||
|
||||
|
||||
class DjangoPlugin(Plugin):
|
||||
def __init__(self, options: Options) -> None:
|
||||
super().__init__(options)
|
||||
|
||||
monkeypatch.restore_original_load_graph()
|
||||
monkeypatch.restore_original_dependencies_handling()
|
||||
|
||||
config_fpath = os.environ.get('MYPY_DJANGO_CONFIG', 'mypy_django.ini')
|
||||
if config_fpath and os.path.exists(config_fpath):
|
||||
self.config = Config.from_config_file(config_fpath)
|
||||
@@ -247,13 +136,6 @@ class DjangoPlugin(Plugin):
|
||||
if 'DJANGO_SETTINGS_MODULE' in os.environ:
|
||||
self.django_settings_module = os.environ['DJANGO_SETTINGS_MODULE']
|
||||
|
||||
settings_modules = ['django.conf.global_settings']
|
||||
if self.django_settings_module:
|
||||
settings_modules.append(self.django_settings_module)
|
||||
|
||||
monkeypatch.add_modules_as_a_source_seed_files(settings_modules)
|
||||
monkeypatch.inject_modules_as_dependencies_for_django_conf_settings(settings_modules)
|
||||
|
||||
def _get_current_model_bases(self) -> Dict[str, int]:
|
||||
model_sym = self.lookup_fully_qualified(helpers.MODEL_CLASS_FULLNAME)
|
||||
if model_sym is not None and isinstance(model_sym.node, TypeInfo):
|
||||
@@ -288,36 +170,71 @@ class DjangoPlugin(Plugin):
|
||||
else:
|
||||
return {}
|
||||
|
||||
def _get_settings_modules_in_order_of_priority(self) -> List[str]:
|
||||
settings_modules = []
|
||||
if self.django_settings_module:
|
||||
settings_modules.append(self.django_settings_module)
|
||||
|
||||
settings_modules.append('django.conf.global_settings')
|
||||
return settings_modules
|
||||
|
||||
def _get_typeinfo_or_none(self, class_name: str) -> Optional[TypeInfo]:
|
||||
sym = self.lookup_fully_qualified(class_name)
|
||||
if sym is not None and isinstance(sym.node, TypeInfo):
|
||||
return sym.node
|
||||
return None
|
||||
|
||||
def get_additional_deps(self, file: MypyFile) -> List[Tuple[int, str, int]]:
|
||||
if file.fullname() == 'django.conf' and self.django_settings_module:
|
||||
return [(10, self.django_settings_module, -1)]
|
||||
|
||||
if file.fullname() == 'django.db.models.query':
|
||||
return [(10, 'mypy_extensions', -1)]
|
||||
|
||||
return []
|
||||
|
||||
def get_function_hook(self, fullname: str
|
||||
) -> Optional[Callable[[FunctionContext], Type]]:
|
||||
if fullname == 'django.contrib.auth.get_user_model':
|
||||
return return_user_model_hook
|
||||
return partial(return_user_model_hook,
|
||||
settings_modules=self._get_settings_modules_in_order_of_priority())
|
||||
|
||||
manager_bases = self._get_current_manager_bases()
|
||||
if fullname in manager_bases:
|
||||
return determine_proper_manager_type
|
||||
|
||||
sym = self.lookup_fully_qualified(fullname)
|
||||
if sym is not None and isinstance(sym.node, TypeInfo):
|
||||
if sym.node.has_base(helpers.FIELD_FULLNAME):
|
||||
info = self._get_typeinfo_or_none(fullname)
|
||||
if info:
|
||||
if info.has_base(helpers.FIELD_FULLNAME):
|
||||
return fields.adjust_return_type_of_field_instantiation
|
||||
|
||||
if sym.node.metadata.get('django', {}).get('generated_init'):
|
||||
if helpers.get_django_metadata(info).get('generated_init'):
|
||||
return init_create.redefine_and_typecheck_model_init
|
||||
|
||||
def get_method_hook(self, fullname: str
|
||||
) -> Optional[Callable[[MethodContext], Type]]:
|
||||
class_name, _, method_name = fullname.rpartition('.')
|
||||
|
||||
if method_name == 'get_form_class':
|
||||
sym = self.lookup_fully_qualified(class_name)
|
||||
if sym and isinstance(sym.node, TypeInfo) and sym.node.has_base(helpers.FORM_MIXIN_CLASS_FULLNAME):
|
||||
info = self._get_typeinfo_or_none(class_name)
|
||||
if info and info.has_base(helpers.FORM_MIXIN_CLASS_FULLNAME):
|
||||
return extract_proper_type_for_get_form_class
|
||||
|
||||
if method_name == 'get_form':
|
||||
sym = self.lookup_fully_qualified(class_name)
|
||||
if sym and isinstance(sym.node, TypeInfo) and sym.node.has_base(helpers.FORM_MIXIN_CLASS_FULLNAME):
|
||||
info = self._get_typeinfo_or_none(class_name)
|
||||
if info and info.has_base(helpers.FORM_MIXIN_CLASS_FULLNAME):
|
||||
return extract_proper_type_for_get_form
|
||||
|
||||
if method_name == 'values':
|
||||
model_info = self._get_typeinfo_or_none(class_name)
|
||||
if model_info and model_info.has_base(helpers.QUERYSET_CLASS_FULLNAME):
|
||||
return extract_proper_type_for_queryset_values
|
||||
|
||||
if method_name == 'values_list':
|
||||
model_info = self._get_typeinfo_or_none(class_name)
|
||||
if model_info and model_info.has_base(helpers.QUERYSET_CLASS_FULLNAME):
|
||||
return extract_proper_type_queryset_values_list
|
||||
|
||||
if fullname in {'django.apps.registry.Apps.get_model',
|
||||
'django.db.migrations.state.StateApps.get_model'}:
|
||||
return determine_model_cls_from_string_for_migrations
|
||||
@@ -330,15 +247,9 @@ class DjangoPlugin(Plugin):
|
||||
|
||||
def get_base_class_hook(self, fullname: str
|
||||
) -> Optional[Callable[[ClassDefContext], None]]:
|
||||
if fullname == helpers.DUMMY_SETTINGS_BASE_CLASS:
|
||||
settings_modules = ['django.conf.global_settings']
|
||||
if self.django_settings_module:
|
||||
settings_modules.append(self.django_settings_module)
|
||||
return AddSettingValuesToDjangoConfObject(settings_modules,
|
||||
self.config.ignore_missing_settings)
|
||||
|
||||
if fullname in self._get_current_model_bases():
|
||||
return transform_model_class
|
||||
return partial(transform_model_class,
|
||||
ignore_missing_model_attributes=self.config.ignore_missing_model_attributes)
|
||||
|
||||
if fullname in self._get_current_manager_bases():
|
||||
return transform_manager_class
|
||||
@@ -346,25 +257,34 @@ class DjangoPlugin(Plugin):
|
||||
if fullname in self._get_current_form_bases():
|
||||
return transform_form_class
|
||||
|
||||
sym = self.lookup_fully_qualified(fullname)
|
||||
if sym and isinstance(sym.node, TypeInfo) and sym.node.has_base(helpers.FORM_MIXIN_CLASS_FULLNAME):
|
||||
info = self._get_typeinfo_or_none(fullname)
|
||||
if info and info.has_base(helpers.FORM_MIXIN_CLASS_FULLNAME):
|
||||
return transform_form_view
|
||||
|
||||
return None
|
||||
|
||||
def get_attribute_hook(self, fullname: str
|
||||
) -> Optional[Callable[[AttributeContext], Type]]:
|
||||
if fullname == 'builtins.object.id':
|
||||
return return_integer_type_for_id_for_non_defined_primary_key_in_models
|
||||
class_name, _, attr_name = fullname.rpartition('.')
|
||||
if class_name == helpers.DUMMY_SETTINGS_BASE_CLASS:
|
||||
return partial(get_type_of_setting,
|
||||
setting_name=attr_name,
|
||||
settings_modules=self._get_settings_modules_in_order_of_priority(),
|
||||
ignore_missing_settings=self.config.ignore_missing_settings)
|
||||
|
||||
module, _, name = fullname.rpartition('.')
|
||||
sym = self.lookup_fully_qualified('django.conf.LazySettings')
|
||||
if sym and isinstance(sym.node, TypeInfo):
|
||||
metadata = get_settings_metadata(sym.node)
|
||||
if module == 'builtins.object' and name in metadata:
|
||||
return ExtractSettingType(module_fullname=metadata[name])
|
||||
if class_name in self._get_current_model_bases():
|
||||
if attr_name == 'id':
|
||||
return return_type_for_id_field
|
||||
|
||||
return extract_and_return_primary_key_of_bound_related_field_parameter
|
||||
model_info = self._get_typeinfo_or_none(class_name)
|
||||
if model_info:
|
||||
related_managers = helpers.get_related_managers_metadata(model_info)
|
||||
if attr_name in related_managers:
|
||||
return partial(determine_type_of_related_manager,
|
||||
related_manager_name=attr_name)
|
||||
|
||||
if attr_name.endswith('_id'):
|
||||
return extract_and_return_primary_key_of_bound_related_field_parameter
|
||||
|
||||
def get_type_analyze_hook(self, fullname: str
|
||||
) -> Optional[Callable[[AnalyzeTypeContext], Type]]:
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from mypy import build
|
||||
from mypy.build import BuildManager, Graph, State
|
||||
from mypy.modulefinder import BuildSource
|
||||
|
||||
old_load_graph = build.load_graph
|
||||
OldState = build.State
|
||||
|
||||
|
||||
def is_module_present_in_sources(module_name: str, sources: List[BuildSource]):
|
||||
return any([source.module == module_name for source in sources])
|
||||
|
||||
|
||||
def add_modules_as_a_source_seed_files(modules: List[str]) -> None:
|
||||
def patched_load_graph(sources: List[BuildSource], manager: BuildManager,
|
||||
old_graph: Optional[Graph] = None,
|
||||
new_modules: Optional[List[State]] = None):
|
||||
# add global settings
|
||||
for module_name in modules:
|
||||
if not is_module_present_in_sources(module_name, sources):
|
||||
sources.append(BuildSource(None, module_name, None))
|
||||
|
||||
return old_load_graph(sources=sources, manager=manager,
|
||||
old_graph=old_graph,
|
||||
new_modules=new_modules)
|
||||
|
||||
build.load_graph = patched_load_graph
|
||||
|
||||
|
||||
def restore_original_load_graph():
|
||||
from mypy import build
|
||||
|
||||
build.load_graph = old_load_graph
|
||||
|
||||
|
||||
def inject_modules_as_dependencies_for_django_conf_settings(modules: List[str]) -> None:
|
||||
from mypy import build
|
||||
|
||||
class PatchedState(build.State):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if self.id == 'django.conf':
|
||||
self.dependencies.extend(modules)
|
||||
|
||||
build.State = PatchedState
|
||||
|
||||
|
||||
def restore_original_dependencies_handling():
|
||||
from mypy import build
|
||||
|
||||
build.State = OldState
|
||||
@@ -1,10 +1,10 @@
|
||||
from typing import Optional, cast
|
||||
|
||||
from mypy.checker import TypeChecker
|
||||
from mypy.nodes import ListExpr, NameExpr, StrExpr, TupleExpr, TypeInfo, Var
|
||||
from mypy.nodes import ListExpr, NameExpr, StrExpr, TupleExpr, TypeInfo
|
||||
from mypy.plugin import FunctionContext
|
||||
from mypy.types import (
|
||||
AnyType, CallableType, Instance, TupleType, Type, TypeOfAny, UnionType,
|
||||
AnyType, CallableType, Instance, TupleType, Type, UnionType,
|
||||
)
|
||||
|
||||
from mypy_django_plugin import helpers
|
||||
@@ -88,23 +88,13 @@ def fill_descriptor_types_for_related_field(ctx: FunctionContext) -> Type:
|
||||
return helpers.reparametrize_instance(ctx.default_return_type, new_args=args)
|
||||
|
||||
|
||||
def get_private_descriptor_type(type_info: TypeInfo, private_field_name: str, is_nullable: bool) -> Type:
|
||||
node = type_info.get(private_field_name).node
|
||||
if isinstance(node, Var):
|
||||
descriptor_type = node.type
|
||||
if is_nullable:
|
||||
descriptor_type = helpers.make_optional(descriptor_type)
|
||||
return descriptor_type
|
||||
return AnyType(TypeOfAny.unannotated)
|
||||
|
||||
|
||||
def set_descriptor_types_for_field(ctx: FunctionContext) -> Instance:
|
||||
default_return_type = cast(Instance, ctx.default_return_type)
|
||||
is_nullable = helpers.parse_bool(helpers.get_argument_by_name(ctx, 'null'))
|
||||
set_type = get_private_descriptor_type(default_return_type.type, '_pyi_private_set_type',
|
||||
is_nullable=is_nullable)
|
||||
get_type = get_private_descriptor_type(default_return_type.type, '_pyi_private_get_type',
|
||||
is_nullable=is_nullable)
|
||||
set_type = helpers.get_private_descriptor_type(default_return_type.type, '_pyi_private_set_type',
|
||||
is_nullable=is_nullable)
|
||||
get_type = helpers.get_private_descriptor_type(default_return_type.type, '_pyi_private_get_type',
|
||||
is_nullable=is_nullable)
|
||||
return helpers.reparametrize_instance(default_return_type, [set_type, get_type])
|
||||
|
||||
|
||||
@@ -159,7 +149,7 @@ def record_field_properties_into_outer_model_class(ctx: FunctionContext) -> None
|
||||
if field_name is None:
|
||||
return
|
||||
|
||||
fields_metadata = outer_model.metadata.setdefault('django', {}).setdefault('fields', {})
|
||||
fields_metadata = helpers.get_fields_metadata(outer_model)
|
||||
|
||||
# primary key
|
||||
is_primary_key = False
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from mypy.plugin import ClassDefContext
|
||||
from mypy.plugin import ClassDefContext, MethodContext
|
||||
from mypy.types import CallableType, Instance, NoneTyp, Type, TypeType
|
||||
|
||||
from mypy_django_plugin import helpers
|
||||
|
||||
@@ -8,3 +9,38 @@ def make_meta_nested_class_inherit_from_any(ctx: ClassDefContext) -> None:
|
||||
if meta_node is None:
|
||||
return None
|
||||
meta_node.fallback_to_any = True
|
||||
|
||||
|
||||
def extract_proper_type_for_get_form(ctx: MethodContext) -> Type:
|
||||
object_type = ctx.type
|
||||
if not isinstance(object_type, Instance):
|
||||
return ctx.default_return_type
|
||||
|
||||
form_class_type = helpers.get_argument_type_by_name(ctx, 'form_class')
|
||||
if form_class_type is None or isinstance(form_class_type, NoneTyp):
|
||||
# extract from specified form_class in metadata
|
||||
form_class_fullname = helpers.get_django_metadata(object_type.type).get('form_class', None)
|
||||
if not form_class_fullname:
|
||||
return ctx.default_return_type
|
||||
|
||||
return ctx.api.named_generic_type(form_class_fullname, [])
|
||||
|
||||
if isinstance(form_class_type, TypeType) and isinstance(form_class_type.item, Instance):
|
||||
return form_class_type.item
|
||||
|
||||
if isinstance(form_class_type, CallableType) and isinstance(form_class_type.ret_type, Instance):
|
||||
return form_class_type.ret_type
|
||||
|
||||
return ctx.default_return_type
|
||||
|
||||
|
||||
def extract_proper_type_for_get_form_class(ctx: MethodContext) -> Type:
|
||||
object_type = ctx.type
|
||||
if not isinstance(object_type, Instance):
|
||||
return ctx.default_return_type
|
||||
|
||||
form_class_fullname = helpers.get_django_metadata(object_type.type).get('form_class', None)
|
||||
if not form_class_fullname:
|
||||
return ctx.default_return_type
|
||||
|
||||
return TypeType(ctx.api.named_generic_type(form_class_fullname, []))
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user