]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Add generic type parameters to FormData (#1651)
authorAdrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Thu, 26 May 2022 19:33:40 +0000 (12:33 -0700)
committerGitHub <noreply@github.com>
Thu, 26 May 2022 19:33:40 +0000 (12:33 -0700)
* Add generic type parameters to FormData

* fix tests

starlette/datastructures.py
tests/test_formparsers.py

index 7aae90ec7bc1c1de0933f62237a68f0dbfe30a45..f49dbc35e3322c098f3a4beb469e0b7822c1db9c 100644 (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.
     """
index 7418595cfeb85e79aae2b777e51ec0ee5afd9065..b7f8cad8c8c13e2d641351531f46c53d145e99f7 100644 (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()