]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Support python-multipart 0.0.12 (#2708)
authorMarcelo Trylesinski <marcelotryle@gmail.com>
Sun, 29 Sep 2024 08:28:34 +0000 (10:28 +0200)
committerGitHub <noreply@github.com>
Sun, 29 Sep 2024 08:28:34 +0000 (10:28 +0200)
14 files changed:
pyproject.toml
starlette/applications.py
starlette/formparsers.py
starlette/requests.py
starlette/routing.py
starlette/schemas.py
starlette/templating.py
tests/middleware/test_errors.py
tests/test_authentication.py
tests/test_concurrency.py
tests/test_exceptions.py
tests/test_responses.py
tests/test_routing.py
tests/test_websockets.py

index b993c2a2d62094cd5b336c0d0b828eaf5cb83bae..a532e46285aadd6b10aad509f9419fd970563980 100644 (file)
@@ -100,7 +100,6 @@ source_pkgs = ["starlette", "tests"]
 [tool.coverage.report]
 exclude_lines = [
     "pragma: no cover",
-    "pragma: nocover",
     "if typing.TYPE_CHECKING:",
     "@typing.overload",
     "raise NotImplementedError",
index f34e80ead67fb72122bb9227aabe518fe0bf26a2..0feae72e411e5a0cc97c7aead431cdb918245745 100644 (file)
@@ -113,7 +113,7 @@ class Starlette:
         await self.middleware_stack(scope, receive, send)
 
     def on_event(self, event_type: str) -> typing.Callable:  # type: ignore[type-arg]
-        return self.router.on_event(event_type)  # pragma: nocover
+        return self.router.on_event(event_type)  # pragma: no cover
 
     def mount(self, path: str, app: ASGIApp, name: str | None = None) -> None:
         self.router.mount(path, app=app, name=name)  # pragma: no cover
index 56f63a8be9013453e5d82a084e65ac273eccf33c..48b0f2aad66a2bf4f0018f22c59821eb3005d90a 100644 (file)
@@ -11,9 +11,12 @@ from starlette.datastructures import FormData, Headers, UploadFile
 try:
     import multipart
     from multipart.multipart import parse_options_header
-except ModuleNotFoundError:  # pragma: nocover
-    parse_options_header = None
-    multipart = None
+except ModuleNotFoundError:  # pragma: no cover
+    parse_options_header = None  # type: ignore
+    multipart = None  # type: ignore
+
+if typing.TYPE_CHECKING:
+    from multipart.multipart import MultipartCallbacks, QuerystringCallbacks
 
 
 class FormMessage(Enum):
@@ -74,7 +77,7 @@ class FormParser:
 
     async def parse(self) -> FormData:
         # Callbacks dictionary.
-        callbacks = {
+        callbacks: QuerystringCallbacks = {
             "on_field_start": self.on_field_start,
             "on_field_name": self.on_field_name,
             "on_field_data": self.on_field_data,
@@ -220,7 +223,7 @@ class MultiPartParser:
             raise MultiPartException("Missing boundary in multipart.")
 
         # Callbacks dictionary.
-        callbacks = {
+        callbacks: MultipartCallbacks = {
             "on_part_begin": self.on_part_begin,
             "on_part_data": self.on_part_data,
             "on_part_end": self.on_part_end,
index 26c13d1cab4448e556f5da251b5173d85c2d7fee..08dbd84d42fd027d6f5f17ee29f8875acc6fc46c 100644 (file)
@@ -14,8 +14,8 @@ from starlette.types import Message, Receive, Scope, Send
 
 try:
     from multipart.multipart import parse_options_header
-except ModuleNotFoundError:  # pragma: nocover
-    parse_options_header = None
+except ModuleNotFoundError:  # pragma: no cover
+    parse_options_header = None  # type: ignore
 
 
 if typing.TYPE_CHECKING:
index cde771563b35709ab0dce9b1b4c99802fa916966..1504ef50a016b973492de7a51aafa5f35d149a66 100644 (file)
@@ -767,7 +767,7 @@ class Router:
     def __eq__(self, other: typing.Any) -> bool:
         return isinstance(other, Router) and self.routes == other.routes
 
-    def mount(self, path: str, app: ASGIApp, name: str | None = None) -> None:  # pragma: nocover
+    def mount(self, path: str, app: ASGIApp, name: str | None = None) -> None:  # pragma: no cover
         route = Mount(path, app=app, name=name)
         self.routes.append(route)
 
@@ -782,7 +782,7 @@ class Router:
         methods: list[str] | None = None,
         name: str | None = None,
         include_in_schema: bool = True,
-    ) -> None:  # pragma: nocover
+    ) -> None:  # pragma: no cover
         route = Route(
             path,
             endpoint=endpoint,
index 94b9cca78307818149a12b440d8fb88756ee666b..bfc40e2ae0efddee75d0328cbe83720b8d80d886 100644 (file)
@@ -10,7 +10,7 @@ from starlette.routing import BaseRoute, Host, Mount, Route
 
 try:
     import yaml
-except ModuleNotFoundError:  # pragma: nocover
+except ModuleNotFoundError:  # pragma: no cover
     yaml = None  # type: ignore[assignment]
 
 
index 48e54c0cc782a3c172f187dcd3a263be636246c5..17e7fa4dcf33dd6d6c047ab8e649de267637916c 100644 (file)
@@ -19,9 +19,9 @@ try:
     # adding a type ignore for mypy to let us access an attribute that may not exist
     if hasattr(jinja2, "pass_context"):
         pass_context = jinja2.pass_context
-    else:  # pragma: nocover
+    else:  # pragma: no cover
         pass_context = jinja2.contextfunction  # type: ignore[attr-defined]
-except ModuleNotFoundError:  # pragma: nocover
+except ModuleNotFoundError:  # pragma: no cover
     jinja2 = None  # type: ignore[assignment]
 
 
index e32f406ae52d5e1cf85ce0171cac78d4815a5b34..0b0f7e51dfc3e4df22d71d2f6de55e36f0e403f7 100644 (file)
@@ -77,7 +77,7 @@ def test_debug_not_http(test_client_factory: TestClientFactory) -> None:
     with pytest.raises(RuntimeError):
         client = test_client_factory(app)
         with client.websocket_connect("/"):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 def test_background_task(test_client_factory: TestClientFactory) -> None:
index a1bde67b9beb59f8b6a10705386d77f5aaf213fe..3c013a3a721579e474f4d6bd393e5e2c8b4a26fa 100644 (file)
@@ -211,7 +211,7 @@ def test_invalid_decorator_usage() -> None:
 
         @requires("authenticated")
         def foo() -> None:
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 def test_user_interface(test_client_factory: TestClientFactory) -> None:
@@ -281,11 +281,11 @@ def test_websocket_authentication_required(
     with test_client_factory(app) as client:
         with pytest.raises(WebSocketDisconnect):
             with client.websocket_connect("/ws"):
-                pass  # pragma: nocover
+                pass  # pragma: no cover
 
         with pytest.raises(WebSocketDisconnect):
             with client.websocket_connect("/ws", headers={"Authorization": "basic foobar"}):
-                pass  # pragma: nocover
+                pass  # pragma: no cover
 
         with client.websocket_connect("/ws", auth=("tomchristie", "example")) as websocket:
             data = websocket.receive_json()
@@ -293,11 +293,11 @@ def test_websocket_authentication_required(
 
         with pytest.raises(WebSocketDisconnect):
             with client.websocket_connect("/ws/decorated"):
-                pass  # pragma: nocover
+                pass  # pragma: no cover
 
         with pytest.raises(WebSocketDisconnect):
             with client.websocket_connect("/ws/decorated", headers={"Authorization": "basic foobar"}):
-                pass  # pragma: nocover
+                pass  # pragma: no cover
 
         with client.websocket_connect("/ws/decorated", auth=("tomchristie", "example")) as websocket:
             data = websocket.receive_json()
index bac6814e42cc99327395426d71607a202156d877..380eb9ef2ae4a7dcec41cf0d3a16b6e52190923c 100644 (file)
@@ -22,8 +22,8 @@ async def test_run_until_first_complete() -> None:
 
     async def task2() -> None:
         await task1_finished.wait()
-        await anyio.sleep(0)  # pragma: nocover
-        task2_finished.set()  # pragma: nocover
+        await anyio.sleep(0)  # pragma: no cover
+        task2_finished.set()  # pragma: no cover
 
     await run_until_first_complete((task1, {}), (task2, {}))
     assert task1_finished.is_set()
index b3dc7843fbb5fc5ba7f8ccf21b9d1af879edf865..eebee3759f92f5530fbc8589007da88f5c668cbe 100644 (file)
@@ -111,7 +111,7 @@ def test_with_headers(client: TestClient) -> None:
 def test_websockets_should_raise(client: TestClient) -> None:
     with pytest.raises(RuntimeError):
         with client.websocket_connect("/runtime_error"):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 def test_handled_exc_after_response(
index 1fb8c6be0a6e8da630659842724f2e14c19d4aa6..be0701a5cfc5d4a55f8ab45b4c9058e276b4af19 100644 (file)
@@ -83,7 +83,7 @@ def test_redirect_response_content_length_header(
 ) -> None:
     async def app(scope: Scope, receive: Receive, send: Send) -> None:
         if scope["path"] == "/":
-            response = Response("hello", media_type="text/plain")  # pragma: nocover
+            response = Response("hello", media_type="text/plain")  # pragma: no cover
         else:
             response = RedirectResponse("/")
         await response(scope, receive, send)
index 6bb398ba5d7fa69ff11bba4313ee2fb1c4902139..fb2bfeec10732b7b5428f5d7679c36314a50790b 100644 (file)
@@ -365,7 +365,7 @@ def test_protocol_switch(test_client_factory: TestClientFactory) -> None:
 
     with pytest.raises(WebSocketDisconnect):
         with client.websocket_connect("/404"):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 ok = PlainTextResponse("OK")
@@ -598,7 +598,7 @@ def test_standalone_ws_route_does_not_match(
     client = test_client_factory(app)
     with pytest.raises(WebSocketDisconnect):
         with client.websocket_connect("/invalid"):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 def test_lifespan_async(test_client_factory: TestClientFactory) -> None:
@@ -795,7 +795,7 @@ def test_raise_on_startup(test_client_factory: TestClientFactory) -> None:
 
     with pytest.raises(RuntimeError):
         with test_client_factory(app):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
     assert startup_failed
 
 
@@ -808,7 +808,7 @@ def test_raise_on_shutdown(test_client_factory: TestClientFactory) -> None:
 
     with pytest.raises(RuntimeError):
         with test_client_factory(app):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 def test_partial_async_endpoint(test_client_factory: TestClientFactory) -> None:
@@ -1186,7 +1186,7 @@ def test_decorator_deprecations() -> None:
 
     with pytest.deprecated_call():
 
-        async def startup() -> None: ...  # pragma: nocover
+        async def startup() -> None: ...  # pragma: no cover
 
         router.on_event("startup")(startup)
 
index 7a9b9272aba9278f9f04c8866657706b9c20faaa..8ecf6304c88ab3be9659d298923ed261fe129cb8 100644 (file)
@@ -529,7 +529,7 @@ def test_receive_json_invalid_mode(test_client_factory: TestClientFactory) -> No
     client = test_client_factory(app)
     with pytest.raises(RuntimeError):
         with client.websocket_connect("/"):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 def test_receive_text_before_accept(test_client_factory: TestClientFactory) -> None:
@@ -540,7 +540,7 @@ def test_receive_text_before_accept(test_client_factory: TestClientFactory) -> N
     client = test_client_factory(app)
     with pytest.raises(RuntimeError):
         with client.websocket_connect("/"):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 def test_receive_bytes_before_accept(test_client_factory: TestClientFactory) -> None:
@@ -551,7 +551,7 @@ def test_receive_bytes_before_accept(test_client_factory: TestClientFactory) ->
     client = test_client_factory(app)
     with pytest.raises(RuntimeError):
         with client.websocket_connect("/"):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 def test_receive_json_before_accept(test_client_factory: TestClientFactory) -> None:
@@ -573,7 +573,7 @@ def test_send_before_accept(test_client_factory: TestClientFactory) -> None:
     client = test_client_factory(app)
     with pytest.raises(RuntimeError):
         with client.websocket_connect("/"):
-            pass  # pragma: nocover
+            pass  # pragma: no cover
 
 
 def test_send_wrong_message_type(test_client_factory: TestClientFactory) -> None: