diff --git a/django-stubs/contrib/postgres/forms/__init__.pyi b/django-stubs/contrib/postgres/forms/__init__.pyi new file mode 100644 index 000000000..50446d589 --- /dev/null +++ b/django-stubs/contrib/postgres/forms/__init__.pyi @@ -0,0 +1,4 @@ +from .array import * +from .hstore import * +from .jsonb import * +from .ranges import * diff --git a/django-stubs/contrib/postgres/forms/array.pyi b/django-stubs/contrib/postgres/forms/array.pyi new file mode 100644 index 000000000..8fecba595 --- /dev/null +++ b/django-stubs/contrib/postgres/forms/array.pyi @@ -0,0 +1,40 @@ +from typing import Any, Iterable, List, Optional, Type, Union + +from django import forms as forms + +class SimpleArrayField(forms.CharField): + base_field: forms.Field = ... + delimiter: str = ... + min_length: Optional[Union[int, str]] = ... + max_length: Optional[Union[int, str]] = ... + def __init__( + self, + base_field: forms.Field, + *, + delimiter: str = ..., + max_length: Optional[Any] = ..., + min_length: Optional[Any] = ..., + **kwargs: Any + ) -> None: ... + def to_python(self, value: Optional[Iterable]) -> List: ... + def validate(self, value: Optional[Iterable]) -> None: ... + def run_validators(self, value: Optional[Iterable]) -> None: ... + +class SplitArrayWidget(forms.Widget): + template_name: str = ... + widget: forms.Widget = ... + size: int = ... + def __init__(self, widget: Union[forms.Widget, Type[forms.Widget]], size: int, **kwargs: Any) -> None: ... + def value_from_datadict(self, data: Dict[str, Any], files: Mapping[str, Iterable[Any]], name: str) -> List: ... + @property + def needs_multipart_form(self) -> bool: ... + +class SplitArrayField(forms.Field): + base_field: forms.Field = ... + size: int = ... + remove_trailing_nulls: bool = ... + def __init__( + self, base_field: forms.Field, size: int, *, remove_trailing_nulls: bool = ..., **kwargs: Any + ) -> None: ... + def to_python(self, value: Optional[Iterable]) -> List: ... + def clean(self, value: Any) -> List: ... diff --git a/django-stubs/contrib/postgres/forms/hstore.pyi b/django-stubs/contrib/postgres/forms/hstore.pyi new file mode 100644 index 000000000..25adbddda --- /dev/null +++ b/django-stubs/contrib/postgres/forms/hstore.pyi @@ -0,0 +1,3 @@ +from django import forms + +class HStoreField(forms.CharField): ... diff --git a/django-stubs/contrib/postgres/forms/jsonb.pyi b/django-stubs/contrib/postgres/forms/jsonb.pyi new file mode 100644 index 000000000..0f1a620d7 --- /dev/null +++ b/django-stubs/contrib/postgres/forms/jsonb.pyi @@ -0,0 +1,8 @@ +from django import forms +from typing import Any + +class InvalidJSONInput(str): ... +class JSONString(str): ... + +class JSONField(forms.CharField): + def prepare_value(self, value: Any) -> str: ... diff --git a/django-stubs/contrib/postgres/forms/ranges.pyi b/django-stubs/contrib/postgres/forms/ranges.pyi new file mode 100644 index 000000000..afc3c58de --- /dev/null +++ b/django-stubs/contrib/postgres/forms/ranges.pyi @@ -0,0 +1,18 @@ +from django import forms +from django.forms.widgets import MultiWidget +from typing import Any, Callable, Optional + +_OptAttrs = Dict[str, Any] + +class BaseRangeField(forms.MultiValueField): + def __init__(self, **kwargs: Any) -> None: ... + def compress(self, values: Any) -> Tuple[Optional[Callable], Optional[Callable]]: ... + +class IntegerRangeField(BaseRangeField): ... +class FloatRangeField(BaseRangeField): ... +class DateTimeRangeField(BaseRangeField): ... +class DateRangeField(BaseRangeField): ... + +class RangeWidget(MultiWidget): + def __init__(self, base_widget: forms.Widget, attrs: Optional[_OptAttrs] = ...) -> None: ... + def decompress(self, value: Any) -> List: ... diff --git a/django-stubs/contrib/postgres/utils.pyi b/django-stubs/contrib/postgres/utils.pyi new file mode 100644 index 000000000..84ebf86e4 --- /dev/null +++ b/django-stubs/contrib/postgres/utils.pyi @@ -0,0 +1,5 @@ +from typing import Mapping + +from django.core.exceptions import ValidationError + +def prefix_validation_error(error: ValidationError, prefix: str, code: str, params: Mapping) -> ValidationError: ... diff --git a/django-stubs/forms/fields.pyi b/django-stubs/forms/fields.pyi index 566ca1183..cb4a2e0a3 100644 --- a/django-stubs/forms/fields.pyi +++ b/django-stubs/forms/fields.pyi @@ -28,7 +28,7 @@ class Field: validators: List[BaseValidator] = ... max_length: Optional[Union[int, str]] = ... choices: _FieldChoices = ... - base_field: Field + base_field: Union[Field, Type[Field]] def __init__( self, *, diff --git a/scripts/enabled_test_modules.py b/scripts/enabled_test_modules.py index b1b5345d5..3c08a5c79 100644 --- a/scripts/enabled_test_modules.py +++ b/scripts/enabled_test_modules.py @@ -334,6 +334,9 @@ 'Incompatible types in assignment (expression has type "Type[Field[Any, Any]]', 'Argument "encoder" to "JSONField" has incompatible type "DjangoJSONEncoder";', '("None" and "SearchQuery")', + 'Too few arguments for "get_context" of "Widget"', + 'Incompatible types in assignment (expression has type "Type[Input]", base class ' + '"Field" defined the type as "Widget")', ], 'properties': [ re.compile('Unexpected attribute "(full_name|full_name_2)" for model "Person"')