From 14ef6bbbd6c5f03f0e1222a0a1b33ccc3a5f04cf Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Thu, 26 May 2022 12:33:40 -0700 Subject: [PATCH] Add generic type parameters to FormData (#1651) * Add generic type parameters to FormData * fix tests --- starlette/datastructures.py | 2 +- tests/test_formparsers.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/starlette/datastructures.py b/starlette/datastructures.py index 7aae90ec..f49dbc35 100644 --- a/starlette/datastructures.py +++ b/starlette/datastructures.py @@ -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. """ diff --git a/tests/test_formparsers.py b/tests/test_formparsers.py index 7418595c..b7f8cad8 100644 --- a/tests/test_formparsers.py +++ b/tests/test_formparsers.py @@ -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()