django-stubs
django-stubs copied to clipboard
request.FILES should respect settings.FILE_UPLOAD_HANDLERS
Bug report
What's wrong
Currently, trying to use an attribute of a file from request.FILES that I know exists because I've set settings.FILE_UPLOAD_HANDLERS explicitly still results in a type checking error like the following:
views.py:135: error: "UploadedFile" has no attribute "temporary_file_path"
How is that should be
If you've set settings.FILE_UPLOAD_HANDLERS explicitly (either always forcing in-memory files or temporary uploaded files, or having your own custom handler class), then request.FILES should be expected to be a list of the type returned by the upload handler.
This can be worked around by adding something like the following before using the attribute:
assert type(the_file) is TemporaryUploadedFile
System information
- OS: macOS
pythonversion: 3.10djangoversion: 4.0.1mypyversion: 0.961django-stubsversion: 1.12.0django-stubs-extversion: N/A