From 6e5f5f2cdba053f5412247b62e3680221164ebcf Mon Sep 17 00:00:00 2001 From: Jonathan Moss Date: Fri, 28 Aug 2020 17:14:57 +1000 Subject: [PATCH] Allows FileField storage to be a Callable (#453) * Allows FileField storage to be a Callable The `storage` parameter of `FileField` (and by extension `ImageField`) is not limited to just taking an instance of `Storage`. It can also take a no-args callable that returns an instance of `Storage`. * correcting linting issue in forms.pyi --- django-stubs/db/models/fields/files.pyi | 2 +- django-stubs/forms/forms.pyi | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/django-stubs/db/models/fields/files.pyi b/django-stubs/db/models/fields/files.pyi index 225d8fd..1fba352 100644 --- a/django-stubs/db/models/fields/files.pyi +++ b/django-stubs/db/models/fields/files.pyi @@ -39,7 +39,7 @@ class FileField(Field): def __init__( self, upload_to: Union[str, Callable, Path] = ..., - storage: Optional[Storage] = ..., + storage: Optional[Union[Storage, Callable[[], Storage]]] = ..., verbose_name: Optional[Union[str, bytes]] = ..., name: Optional[str] = ..., max_length: Optional[int] = ..., diff --git a/django-stubs/forms/forms.pyi b/django-stubs/forms/forms.pyi index bb7be6b..dcb140c 100644 --- a/django-stubs/forms/forms.pyi +++ b/django-stubs/forms/forms.pyi @@ -70,7 +70,12 @@ class BaseForm: def visible_fields(self): ... def get_initial_for_field(self, field: Field, field_name: str) -> Any: ... def _html_output( - self, normal_row: str, error_row: str, row_ender: str, help_text_html: str, errors_on_separate_row: bool, + self, + normal_row: str, + error_row: str, + row_ender: str, + help_text_html: str, + errors_on_separate_row: bool, ) -> SafeText: ... class Form(BaseForm):