You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The filename property of the UploadFile class can be and is None by default.
In what case is this actually useful? When doing a multipart upload, omitting the filename results in Starlette providing the file content as a str, and looking at the form parsing code in formparsers.py I can't really spot a case where an UploadFile is produced without a filename. So I'm left wondering why it's optional.
It's a bit inconvienent when writing code, because our type checker will require us to make sure that the value is not None, however that case does not seem possible, so writing API test code that produces an actual request where this happens does also not seem possible.
Leaving us with the option to either ignore the type checker, or exclude the code that does the None check from our test coverage.
It would seem that the DX could be improved by not having the filename property be optional, but maybe I'm missing something?
Please let me know your thoughts on this. Thanks in advance for your time and effort.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The
filename
property of theUploadFile
class can be and isNone
by default.In what case is this actually useful? When doing a multipart upload, omitting the filename results in Starlette providing the file content as a
str
, and looking at the form parsing code informparsers.py
I can't really spot a case where anUploadFile
is produced without a filename. So I'm left wondering why it's optional.It's a bit inconvienent when writing code, because our type checker will require us to make sure that the value is not
None
, however that case does not seem possible, so writing API test code that produces an actual request where this happens does also not seem possible.Leaving us with the option to either ignore the type checker, or exclude the code that does the
None
check from our test coverage.It would seem that the DX could be improved by not having the
filename
property be optional, but maybe I'm missing something?Please let me know your thoughts on this. Thanks in advance for your time and effort.
Beta Was this translation helpful? Give feedback.
All reactions