django-stubs
django-stubs copied to clipboard
Form.files should be a MultiValueDict
Bug report
In #909, the BaseForm
class's files
attribute (and everything related to it, like the files
argument to Widget.value_from_datadict
) were updated to _FilesT
, which is defined as Mapping[str, Iterable[File]]
. Unless there are counterexamples in the Django codebase that I haven't seen, I'm pretty sure this can be more specific than Mapping
- it appears to be a MultiValueDict
(which is what this was typed as in previous versions of django-stubs).
Is it safe to assume that this is a MultiValueDict
everywhere, or can users only rely on it being a Mapping
?
(disclaimer: it was my commit)
Using Iterable
was definitely a mistake, yes, it should have been Mapping[str, File]
.
I will revert this for now in #925 and use MultiValueDict[str, UploadedFile]
for now again. I see the point that Mapping[str, Iterable[File]]
is absolutely invalid (it doesn't return iterables as values) and Mapping[str, UploadedFile]
doesn't work with multiple files upload (no .getlist
method). However, there's problem with MultiValueDict[str, UploadedFile]
too: it invalidates all test cases where we use MyForm({}, {'file_field': UploadedFile(...)})
.
I think this case needs discussion and mainainer's final decision.
@sobolevn I'm sure you're one of maintainers, please resolve this or ping somebody else :)
@sterliakov thanks for taking a look (and for all the great enhancements you made!)