mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 21:14:49 +08:00
enable 'model_forms' for tests typechecking (#270)
This commit is contained in:
@@ -205,10 +205,9 @@ class CallableChoiceIterator:
|
|||||||
def __iter__(self) -> None: ...
|
def __iter__(self) -> None: ...
|
||||||
|
|
||||||
class ChoiceField(Field):
|
class ChoiceField(Field):
|
||||||
choices: Any = ...
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
choices: Any = ...,
|
choices: _FieldChoices = ...,
|
||||||
required: bool = ...,
|
required: bool = ...,
|
||||||
widget: Optional[Union[Widget, Type[Widget]]] = ...,
|
widget: Optional[Union[Widget, Type[Widget]]] = ...,
|
||||||
label: Optional[Any] = ...,
|
label: Optional[Any] = ...,
|
||||||
|
|||||||
@@ -1,5 +1,21 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Callable, Dict, Iterator, List, Mapping, MutableMapping, Optional, Sequence, Tuple, Type, Union
|
from typing import (
|
||||||
|
Any,
|
||||||
|
Callable,
|
||||||
|
Dict,
|
||||||
|
Iterator,
|
||||||
|
List,
|
||||||
|
Mapping,
|
||||||
|
MutableMapping,
|
||||||
|
Optional,
|
||||||
|
Sequence,
|
||||||
|
Tuple,
|
||||||
|
Type,
|
||||||
|
Union,
|
||||||
|
ClassVar,
|
||||||
|
Container,
|
||||||
|
TypeVar,
|
||||||
|
)
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
@@ -24,6 +40,11 @@ _Fields = Union[List[Union[Callable, str]], Sequence[str], Literal["__all__"]]
|
|||||||
_Labels = Dict[str, str]
|
_Labels = Dict[str, str]
|
||||||
_ErrorMessages = Dict[str, Dict[str, str]]
|
_ErrorMessages = Dict[str, Dict[str, str]]
|
||||||
|
|
||||||
|
_M = TypeVar("_M", bound=Model)
|
||||||
|
|
||||||
|
def construct_instance(
|
||||||
|
form: BaseForm, instance: _M, fields: Optional[Container[str]] = ..., exclude: Optional[Container[str]] = ...
|
||||||
|
) -> _M: ...
|
||||||
def model_to_dict(
|
def model_to_dict(
|
||||||
instance: Model, fields: Optional[_Fields] = ..., exclude: Optional[_Fields] = ...
|
instance: Model, fields: Optional[_Fields] = ..., exclude: Optional[_Fields] = ...
|
||||||
) -> Dict[str, Any]: ...
|
) -> Dict[str, Any]: ...
|
||||||
@@ -76,7 +97,8 @@ class BaseModelForm(BaseForm):
|
|||||||
save_m2m: Any = ...
|
save_m2m: Any = ...
|
||||||
def save(self, commit: bool = ...) -> Any: ...
|
def save(self, commit: bool = ...) -> Any: ...
|
||||||
|
|
||||||
class ModelForm(BaseModelForm): ...
|
class ModelForm(BaseModelForm, metaclass=ModelFormMetaclass):
|
||||||
|
base_fields: ClassVar[Dict[str, Field]] = ...
|
||||||
|
|
||||||
def modelform_factory(
|
def modelform_factory(
|
||||||
model: Type[Model],
|
model: Type[Model],
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
from typing import Any, Callable, Dict, Optional, Sequence, Type, Union
|
from typing import Any, Callable, Dict, Optional, Sequence, Type, Union
|
||||||
|
|
||||||
from django.forms.forms import BaseForm
|
from django.forms.forms import BaseForm
|
||||||
from django.http import HttpRequest, HttpResponse
|
|
||||||
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
|
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
|
||||||
from django.views.generic.detail import BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin
|
from django.views.generic.detail import BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin
|
||||||
from typing_extensions import Literal
|
from typing_extensions import Literal
|
||||||
|
|
||||||
|
from django.http import HttpRequest, HttpResponse
|
||||||
|
|
||||||
class FormMixin(ContextMixin):
|
class FormMixin(ContextMixin):
|
||||||
initial: Dict[str, Any] = ...
|
initial: Dict[str, Any] = ...
|
||||||
form_class: Optional[Type[BaseForm]] = ...
|
form_class: Optional[Type[BaseForm]] = ...
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
IGNORED_MODULES = {'schema', 'gis_tests', 'admin_widgets', 'admin_filters',
|
IGNORED_MODULES = {'schema', 'gis_tests', 'admin_widgets', 'admin_filters',
|
||||||
'sitemaps_tests', 'staticfiles_tests', 'modeladmin', 'model_forms',
|
'sitemaps_tests', 'staticfiles_tests', 'modeladmin',
|
||||||
'generic_views', 'forms_tests', 'flatpages_tests',
|
'generic_views', 'forms_tests', 'flatpages_tests',
|
||||||
'admin_ordering', 'admin_changelist', 'admin_views',
|
'admin_ordering', 'admin_changelist', 'admin_views',
|
||||||
'invalid_models_tests', 'i18n', 'model_formsets',
|
'invalid_models_tests', 'i18n', 'model_formsets',
|
||||||
@@ -283,6 +283,14 @@ IGNORED_ERRORS = {
|
|||||||
'Incompatible type for "size" of "FloatModel" (got "object", expected "Union[float, int, str, Combinable]")',
|
'Incompatible type for "size" of "FloatModel" (got "object", expected "Union[float, int, str, Combinable]")',
|
||||||
'Incompatible type for "value" of "IntegerModel" (got "object", expected',
|
'Incompatible type for "value" of "IntegerModel" (got "object", expected',
|
||||||
],
|
],
|
||||||
|
'model_forms': [
|
||||||
|
'"render" of "Widget"',
|
||||||
|
"Module 'django.core.validators' has no attribute 'ValidationError'",
|
||||||
|
'Incompatible types in assignment',
|
||||||
|
'NewForm',
|
||||||
|
'"type" has no attribute "base_fields"',
|
||||||
|
'Argument "instance" to "InvalidModelForm" has incompatible type "Type[Category]"',
|
||||||
|
],
|
||||||
'model_indexes': [
|
'model_indexes': [
|
||||||
'Argument "condition" to "Index" has incompatible type "str"; expected "Optional[Q]"'
|
'Argument "condition" to "Index" has incompatible type "str"; expected "Optional[Q]"'
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ from scripts.enabled_test_modules import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
DJANGO_COMMIT_REFS: Dict[str, Tuple[str, str]] = {
|
DJANGO_COMMIT_REFS: Dict[str, Tuple[str, str]] = {
|
||||||
'2.2': ('stable/2.2.x', 'e8b0903976077b951795938b260211214ed7fe41'),
|
'2.2': ('stable/2.2.x', '86befcc172c23170a720b3e0c06db51a99b3da59'),
|
||||||
'3.0': ('stable/3.0.x', '7ec5962638144cbf4c2e47ea7d8dc02d1ce44394')
|
'3.0': ('stable/3.0.x', '6cb30414bc0f83b49afc4cae76d4af5656effe9a')
|
||||||
}
|
}
|
||||||
PROJECT_DIRECTORY = Path(__file__).parent.parent
|
PROJECT_DIRECTORY = Path(__file__).parent.parent
|
||||||
DJANGO_SOURCE_DIRECTORY = PROJECT_DIRECTORY / 'django-sources' # type: Path
|
DJANGO_SOURCE_DIRECTORY = PROJECT_DIRECTORY / 'django-sources' # type: Path
|
||||||
|
|||||||
Reference in New Issue
Block a user