From 3bda2b6cd0b85f5eb9866041e65a6dd454721dee Mon Sep 17 00:00:00 2001 From: Alex Nathanail Date: Wed, 10 Aug 2022 13:25:15 +0100 Subject: [PATCH 1/2] Fix base_field type for SimpleArrayField --- django-stubs/contrib/postgres/forms/array.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django-stubs/contrib/postgres/forms/array.pyi b/django-stubs/contrib/postgres/forms/array.pyi index ec24e2aa3..01b5a8c62 100644 --- a/django-stubs/contrib/postgres/forms/array.pyi +++ b/django-stubs/contrib/postgres/forms/array.pyi @@ -13,7 +13,7 @@ from ..utils import prefix_validation_error as prefix_validation_error class SimpleArrayField(forms.CharField): default_error_messages: _ErrorMessagesT = ... - base_field: Type[forms.Field] + base_field: forms.Field delimiter: str min_length: Optional[int] max_length: Optional[int] From 28d6ba783e2dd1f5f1b4335d51333faf144c6b8b Mon Sep 17 00:00:00 2001 From: Alex Nathanail Date: Wed, 10 Aug 2022 12:46:00 +0000 Subject: [PATCH 2/2] Add test which fails without this change --- django-stubs/contrib/postgres/forms/array.pyi | 6 +++--- tests/typecheck/contrib/postgres/test_fields.yml | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/django-stubs/contrib/postgres/forms/array.pyi b/django-stubs/contrib/postgres/forms/array.pyi index 01b5a8c62..f3c859040 100644 --- a/django-stubs/contrib/postgres/forms/array.pyi +++ b/django-stubs/contrib/postgres/forms/array.pyi @@ -19,7 +19,7 @@ class SimpleArrayField(forms.CharField): max_length: Optional[int] def __init__( self, - base_field: Type[forms.Field], + base_field: forms.Field, *, delimiter: str = ..., max_length: Optional[int] = ..., @@ -51,11 +51,11 @@ class SplitArrayWidget(forms.Widget): class SplitArrayField(forms.Field): default_error_messages: _ErrorMessagesT = ... - base_field: Type[forms.Field] + base_field: forms.Field size: int remove_trailing_nulls: bool def __init__( - self, base_field: Type[forms.Field], size: int, *, remove_trailing_nulls: bool = ..., **kwargs: Any + self, base_field: forms.Field, size: int, *, remove_trailing_nulls: bool = ..., **kwargs: Any ) -> None: ... def to_python(self, value: Any) -> Sequence[Any]: ... def clean(self, value: Any) -> Sequence[Any]: ... diff --git a/tests/typecheck/contrib/postgres/test_fields.yml b/tests/typecheck/contrib/postgres/test_fields.yml index 5dc93cfc9..9ede5a0fb 100644 --- a/tests/typecheck/contrib/postgres/test_fields.yml +++ b/tests/typecheck/contrib/postgres/test_fields.yml @@ -17,3 +17,18 @@ class MyModel(models.Model): array = ArrayField(base_field=models.TextField()) +- case: postgres_forms_simple_array_field + main: | + from myapp.forms import MyForm + MyForm() + installed_apps: + - myapp + files: + - path: myapp/__init__.py + - path: myapp/forms.py + content: | + from django import forms + from django.contrib.postgres.forms import SimpleArrayField + + class MyForm(forms.Form): + lots_of_dates = SimpleArrayField(forms.DateField(), required=False)