Add generic type parameters to FormData (#1651)

* Add generic type parameters to FormData

* fix tests
This commit is contained in:
Adrian Garcia Badaracco 2022-05-26 12:33:40 -07:00 committed by GitHub
parent f2ab0a3009
commit 14ef6bbbd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -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.
"""

View File

@ -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()