Skip to content

Commit 5c6be7a

Browse files
authored
Add test to import all modules to check validity of stubs (#56)
* add import_all.test builder * fix errors * fix typechecking errors * fix migrations typechecking
1 parent 5d0ee40 commit 5c6be7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+706
-1155
lines changed

django-stubs/contrib/admin/apps.pyi

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1-
from typing import Any
2-
31
from django.apps import AppConfig
42

53
class SimpleAdminConfig(AppConfig):
6-
apps: None
7-
label: str
8-
models: None
9-
models_module: None
10-
module: Any
11-
path: str
124
default_site: str = ...
13-
name: str = ...
14-
verbose_name: Any = ...
15-
def ready(self) -> None: ...
165

17-
class AdminConfig(SimpleAdminConfig):
18-
apps: None
19-
label: str
20-
models: None
21-
models_module: None
22-
module: Any
23-
name: str
24-
path: str
25-
def ready(self) -> None: ...
6+
class AdminConfig(SimpleAdminConfig): ...

django-stubs/contrib/admin/forms.pyi

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
1-
from typing import Any, Dict
2-
31
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm
4-
from django.contrib.auth.models import User
52

63
class AdminAuthenticationForm(AuthenticationForm):
7-
auto_id: str
8-
data: Dict[str, str]
9-
empty_permitted: bool
10-
error_class: type
11-
fields: Dict[Any, Any]
12-
files: Dict[Any, Any]
13-
initial: Dict[Any, Any]
14-
is_bound: bool
15-
label_suffix: str
16-
request: None
17-
user_cache: None
18-
error_messages: Any = ...
194
required_css_class: str = ...
20-
def confirm_login_allowed(self, user: User) -> None: ...
215

226
class AdminPasswordChangeForm(PasswordChangeForm):
23-
auto_id: str
24-
data: Dict[Any, Any]
25-
empty_permitted: bool
26-
error_class: type
27-
fields: Dict[Any, Any]
28-
files: Dict[Any, Any]
29-
initial: Dict[Any, Any]
30-
is_bound: bool
31-
label_suffix: str
32-
user: Any
337
required_css_class: str = ...

django-stubs/contrib/admin/helpers.pyi

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
1-
import collections
2-
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, Type
1+
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
32

4-
from django import forms
53
from django.contrib.auth.forms import AdminPasswordChangeForm
6-
from django.db.models.fields import AutoField
7-
from django.forms.utils import ErrorDict, ErrorList
4+
from django.forms.boundfield import BoundField
5+
from django.forms.utils import ErrorDict
86
from django.forms.widgets import Media, Widget
97
from django.utils.safestring import SafeText
108

11-
from django.forms.boundfield import BoundField
9+
from django import forms
10+
from django.db.models.fields import AutoField
1211

1312
ACTION_CHECKBOX_NAME: str
1413

1514
class ActionForm(forms.Form):
16-
auto_id: None
17-
data: Dict[Any, Any]
18-
empty_permitted: bool
19-
error_class: Type[ErrorList]
20-
fields: collections.OrderedDict
21-
files: Dict[Any, Any]
22-
initial: Dict[Any, Any]
23-
is_bound: bool
24-
label_suffix: str
2515
action: Any = ...
2616
select_across: Any = ...
2717

@@ -36,8 +26,8 @@ class AdminForm:
3626
form: AdminPasswordChangeForm,
3727
fieldsets: List[Tuple[None, Dict[str, List[str]]]],
3828
prepopulated_fields: Dict[Any, Any],
39-
readonly_fields: None = ...,
40-
model_admin: None = ...,
29+
readonly_fields: Any = ...,
30+
model_admin: Any = ...,
4131
) -> None: ...
4232
def __iter__(self) -> Iterator[Fieldset]: ...
4333
@property
@@ -137,7 +127,6 @@ class InlineAdminFormSet:
137127

138128
class InlineAdminForm(AdminForm):
139129
formset: Any = ...
140-
model_admin: Any = ...
141130
original: Any = ...
142131
show_url: Any = ...
143132
absolute_url: Any = ...
@@ -152,7 +141,6 @@ class InlineAdminForm(AdminForm):
152141
model_admin: Optional[Any] = ...,
153142
view_on_site_url: Optional[Any] = ...,
154143
) -> None: ...
155-
def __iter__(self) -> Iterator[InlineFieldset]: ...
156144
def needs_explicit_pk_field(self) -> Union[bool, AutoField]: ...
157145
def pk_field(self) -> AdminField: ...
158146
def fk_field(self) -> AdminField: ...
@@ -162,9 +150,6 @@ class InlineAdminForm(AdminForm):
162150
class InlineFieldset(Fieldset):
163151
formset: Any = ...
164152
def __init__(self, formset: Any, *args: Any, **kwargs: Any) -> None: ...
165-
def __iter__(self) -> Iterator[Fieldline]: ...
166153

167154
class AdminErrorList(forms.utils.ErrorList):
168-
data: List[Any]
169-
error_class: str
170155
def __init__(self, form: Any, inline_formsets: Any) -> None: ...
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
from typing import Any, Optional
1+
from typing import Any
22

3+
from django.contrib.admin.options import ModelAdmin
34
from django.core.handlers.wsgi import WSGIRequest
4-
from django.core.paginator import Paginator
5-
from django.db.models.query import QuerySet
6-
from django.http.response import JsonResponse
75
from django.views.generic.list import BaseListView
86

97
class AutocompleteJsonView(BaseListView):
10-
paginate_by: int = ...
118
model_admin: ModelAdmin = ...
129
term: Any = ...
13-
paginator_class: Any = ...
14-
object_list: Any = ...
15-
def get(self, request: WSGIRequest, *args: Any, **kwargs: Any) -> JsonResponse: ...
16-
def get_paginator(self, *args: Any, **kwargs: Any) -> Paginator: ...
17-
def get_queryset(self) -> QuerySet: ...
1810
def has_perm(self, request: WSGIRequest, obj: None = ...) -> bool: ...

django-stubs/contrib/admin/widgets.pyi

Lines changed: 15 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,47 @@
1-
from collections import OrderedDict
2-
from datetime import datetime
3-
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
1+
from typing import Any, Dict, List, Optional, Set, Tuple, Union
42
from uuid import UUID
53

4+
from django.contrib.admin.sites import AdminSite
5+
from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToOneRel
66
from django.forms.models import ModelChoiceIterator
7+
from django.forms.widgets import ChoiceWidget, Media
78

89
from django import forms
9-
from django.contrib.admin.sites import AdminSite
10-
from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToOneRel, ManyToManyRel
11-
from django.db.models.query_utils import Q
12-
from django.forms.fields import Field
13-
from django.forms.widgets import ChoiceWidget, Media, Widget, DateTimeBaseInput
14-
from django.http.request import QueryDict
15-
from django.utils.datastructures import MultiValueDict
1610

1711
class FilteredSelectMultiple(forms.SelectMultiple):
1812
@property
1913
def media(self) -> Media: ...
2014
verbose_name: Any = ...
2115
is_stacked: Any = ...
2216
def __init__(self, verbose_name: str, is_stacked: bool, attrs: None = ..., choices: Tuple = ...) -> None: ...
23-
def get_context(
24-
self, name: str, value: Union[List[Any], str], attrs: Optional[Dict[str, str]]
25-
) -> Dict[
26-
str,
27-
Union[
28-
Dict[
29-
str,
30-
Union[
31-
Dict[str, Union[int, str]],
32-
List[Tuple[None, List[Dict[str, Union[Dict[Any, Any], int, str]]], int]],
33-
bool,
34-
str,
35-
],
36-
],
37-
Dict[str, Union[Dict[str, Union[int, str]], List[str], bool, str]],
38-
],
39-
]: ...
4017

4118
class AdminDateWidget(forms.DateInput):
42-
attrs: Dict[str, str]
43-
input_type: str
4419
@property
4520
def media(self) -> Media: ...
46-
def __init__(self, attrs: Optional[Dict[str, Union[int, str]]] = ..., format: None = ...) -> None: ...
4721

4822
class AdminTimeWidget(forms.TimeInput):
49-
attrs: Dict[str, str]
50-
input_type: str
5123
@property
5224
def media(self) -> Media: ...
53-
def __init__(self, attrs: Optional[Dict[str, Union[int, str]]] = ..., format: None = ...) -> None: ...
54-
55-
class AdminSplitDateTime(forms.SplitDateTimeWidget):
56-
attrs: Dict[Any, Any]
57-
widgets: List[DateTimeBaseInput]
58-
template_name: str = ...
59-
def __init__(self, attrs: None = ...) -> None: ...
60-
def get_context(
61-
self, name: str, value: Optional[Union[List[str], datetime]], attrs: Optional[Dict[str, Union[bool, str]]]
62-
) -> Dict[
63-
str,
64-
Union[
65-
Dict[
66-
str,
67-
Optional[
68-
Union[
69-
Dict[str, Union[bool, str]],
70-
List[Dict[str, Optional[Union[Dict[str, Union[bool, str]], bool, str]]]],
71-
bool,
72-
str,
73-
]
74-
],
75-
],
76-
str,
77-
],
78-
]: ...
79-
80-
class AdminRadioSelect(forms.RadioSelect):
81-
attrs: Dict[str, str]
82-
template_name: str = ...
8325

84-
class AdminFileWidget(forms.ClearableFileInput):
85-
attrs: Dict[Any, Any]
86-
template_name: str = ...
26+
class AdminSplitDateTime(forms.SplitDateTimeWidget): ...
27+
class AdminRadioSelect(forms.RadioSelect): ...
28+
class AdminFileWidget(forms.ClearableFileInput): ...
8729

88-
def url_params_from_lookup_dict(
89-
lookups: Union[
90-
Dict[str, Callable], Dict[str, List[str]], Dict[str, Tuple[str, str]], Dict[str, bool], Dict[str, str], Q
91-
]
92-
) -> Dict[str, str]: ...
30+
def url_params_from_lookup_dict(lookups: Any) -> Dict[str, str]: ...
9331

9432
class ForeignKeyRawIdWidget(forms.TextInput):
95-
attrs: Dict[Any, Any]
96-
template_name: str = ...
9733
rel: ManyToOneRel = ...
9834
admin_site: AdminSite = ...
9935
db: None = ...
10036
def __init__(self, rel: ForeignObjectRel, admin_site: AdminSite, attrs: None = ..., using: None = ...) -> None: ...
101-
def get_context(
102-
self, name: str, value: Optional[Union[List[int], int, str, UUID]], attrs: Optional[Dict[str, Union[bool, str]]]
103-
) -> Dict[str, Union[Dict[str, Optional[Union[Dict[str, Union[bool, str]], bool, str]]], str]]: ...
10437
def base_url_parameters(self) -> Dict[str, str]: ...
10538
def url_parameters(self) -> Dict[str, str]: ...
10639
def label_and_url_for_value(self, value: Union[int, str, UUID]) -> Tuple[str, str]: ...
10740

108-
class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
109-
admin_site: AdminSite
110-
attrs: Dict[Any, Any]
111-
db: None
112-
rel: ManyToManyRel
113-
template_name: str = ...
114-
def get_context(
115-
self, name: str, value: Optional[List[int]], attrs: Optional[Dict[str, str]]
116-
) -> Dict[str, Union[Dict[str, Union[Dict[str, str], bool, str]], str]]: ...
117-
def url_parameters(self) -> Dict[Any, Any]: ...
118-
def label_and_url_for_value(self, value: List[int]) -> Tuple[str, str]: ...
119-
def value_from_datadict(self, data: QueryDict, files: MultiValueDict, name: str) -> None: ...
120-
def format_value(self, value: Optional[List[int]]) -> str: ...
41+
class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): ...
12142

12243
class RelatedFieldWidgetWrapper(forms.Widget):
12344
template_name: str = ...
124-
needs_multipart_form: bool = ...
125-
attrs: Dict[Any, Any] = ...
12645
choices: ModelChoiceIterator = ...
12746
widget: AutocompleteSelect = ...
12847
rel: ManyToOneRel = ...
@@ -141,54 +60,19 @@ class RelatedFieldWidgetWrapper(forms.Widget):
14160
can_delete_related: bool = ...,
14261
can_view_related: bool = ...,
14362
) -> None: ...
144-
def __deepcopy__(
145-
self, memo: Dict[int, Union[List[Union[Field, Widget]], OrderedDict, Field, Widget]]
146-
) -> RelatedFieldWidgetWrapper: ...
147-
@property
148-
def is_hidden(self) -> bool: ...
14963
@property
15064
def media(self) -> Media: ...
15165
def get_related_url(self, info: Tuple[str, str], action: str, *args: Any) -> str: ...
152-
def get_context(
153-
self, name: str, value: Optional[Union[int, str]], attrs: Optional[Dict[str, Union[bool, str]]]
154-
) -> Dict[str, Union[bool, str]]: ...
155-
def value_from_datadict(
156-
self, data: QueryDict, files: MultiValueDict, name: str
157-
) -> Optional[Union[List[str], str]]: ...
158-
def value_omitted_from_data(self, data: Dict[Any, Any], files: Dict[Any, Any], name: str) -> bool: ...
159-
def id_for_label(self, id_: str) -> str: ...
160-
161-
class AdminTextareaWidget(forms.Textarea):
162-
attrs: Dict[str, str]
163-
def __init__(self, attrs: None = ...) -> None: ...
164-
165-
class AdminTextInputWidget(forms.TextInput):
166-
attrs: Dict[str, str]
167-
input_type: str
168-
def __init__(self, attrs: None = ...) -> None: ...
169-
170-
class AdminEmailInputWidget(forms.EmailInput):
171-
attrs: Dict[str, str]
172-
input_type: str
173-
def __init__(self, attrs: None = ...) -> None: ...
174-
175-
class AdminURLFieldWidget(forms.URLInput):
176-
attrs: Dict[str, str]
177-
input_type: str
178-
template_name: str = ...
179-
def __init__(self, attrs: None = ...) -> None: ...
180-
def get_context(
181-
self, name: str, value: Optional[str], attrs: Optional[Dict[str, str]]
182-
) -> Dict[str, Union[Dict[str, Optional[Union[Dict[str, str], bool, str]]], str]]: ...
66+
67+
class AdminTextareaWidget(forms.Textarea): ...
68+
class AdminTextInputWidget(forms.TextInput): ...
69+
class AdminEmailInputWidget(forms.EmailInput): ...
70+
class AdminURLFieldWidget(forms.URLInput): ...
18371

18472
class AdminIntegerFieldWidget(forms.NumberInput):
185-
attrs: Dict[str, str]
186-
input_type: str
18773
class_name: str = ...
188-
def __init__(self, attrs: None = ...) -> None: ...
18974

190-
class AdminBigIntegerFieldWidget(AdminIntegerFieldWidget):
191-
class_name: str = ...
75+
class AdminBigIntegerFieldWidget(AdminIntegerFieldWidget): ...
19276

19377
SELECT2_TRANSLATIONS: Any
19478

@@ -208,12 +92,6 @@ class AutocompleteMixin:
20892
using: None = ...,
20993
) -> None: ...
21094
def get_url(self) -> str: ...
211-
def build_attrs(
212-
self, base_attrs: Dict[str, str], extra_attrs: Optional[Dict[str, Union[bool, str]]] = ...
213-
) -> Dict[str, Union[bool, str]]: ...
214-
def optgroups(
215-
self, name: str, value: List[str], attr: Dict[str, Union[bool, str]] = ...
216-
) -> List[Tuple[None, List[Dict[str, Union[Dict[str, bool], Set[str], int, str]]], int]]: ...
21795
@property
21896
def media(self) -> Media: ...
21997

0 commit comments

Comments
 (0)