mirror of https://github.com/encode/starlette.git
Add generic type parameters to FormData (#1651)
* Add generic type parameters to FormData * fix tests
This commit is contained in:
parent
f2ab0a3009
commit
14ef6bbbd6
|
@ -477,7 +477,7 @@ class UploadFile:
|
|||
await run_in_threadpool(self.file.close)
|
||||
|
||||
|
||||
class FormData(ImmutableMultiDict):
|
||||
class FormData(ImmutableMultiDict[str, typing.Union[UploadFile, str]]):
|
||||
"""
|
||||
An immutable multidict, containing both file uploads and text input.
|
||||
"""
|
||||
|
|
|
@ -24,7 +24,7 @@ FORCE_MULTIPART = ForceMultipartDict()
|
|||
async def app(scope, receive, send):
|
||||
request = Request(scope, receive)
|
||||
data = await request.form()
|
||||
output = {}
|
||||
output: typing.Dict[str, typing.Any] = {}
|
||||
for key, value in data.items():
|
||||
if isinstance(value, UploadFile):
|
||||
content = await value.read()
|
||||
|
@ -66,7 +66,7 @@ async def multi_items_app(scope, receive, send):
|
|||
async def app_with_headers(scope, receive, send):
|
||||
request = Request(scope, receive)
|
||||
data = await request.form()
|
||||
output = {}
|
||||
output: typing.Dict[str, typing.Any] = {}
|
||||
for key, value in data.items():
|
||||
if isinstance(value, UploadFile):
|
||||
content = await value.read()
|
||||
|
|
Loading…
Reference in New Issue