From 8c387e85fe5d3c3759b4ecbba643b0f2491fd063 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sat, 12 Jun 2021 00:21:42 +0200 Subject: [PATCH] Allow Collection for 'fields' and 'exclude' of form model helpers (#637) (#640) * Allow Collection for 'fields' and 'exclude' of form model helpers (#637) There are several functions and classes in `django.forms.models` that take a `fields` or `exclude` argument. Previously, `Sequence` was used to annotate these, but the code of Django (I checked version 3.2.4) doesn't require `__getitem__()` to be implemented, so requiring `Collection` instead is sufficient. The practical advantage of requiring `Collection` is that a set, such as the key set of a dictionary, can be passed without first having to convert it to a list or tuple. * Pin mypy to below version 0.900 * Remove Callable for 'fields' and 'exclude' of form model helpers I cannot find any support for callables for these two arguments in the code or in the documentation. * Update setup.py Co-authored-by: Nikita Sobolev --- django-stubs/forms/models.pyi | 3 ++- setup.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index 1cb275f..2e471de 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -2,6 +2,7 @@ from datetime import datetime from typing import ( Any, Callable, + Collection, Dict, Iterator, List, @@ -36,7 +37,7 @@ from django.db.models import ForeignKey ALL_FIELDS: str -_Fields = Union[List[Union[Callable, str]], Sequence[str], Literal["__all__"]] +_Fields = Union[Collection[str], Literal["__all__"]] _Labels = Dict[str, str] _ErrorMessages = Dict[str, Dict[str, str]] diff --git a/setup.py b/setup.py index 63b28bd..6381f70 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ with open("README.md") as f: readme = f.read() dependencies = [ - "mypy>=0.790", + "mypy>=0.900", "typing-extensions", "django", "django-stubs-ext",