Skip to content

Commit

Permalink
Support python-multipart 0.0.12 (#2708)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored Sep 29, 2024
1 parent fa7b382 commit 1a6018e
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 33 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion starlette/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
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
Expand Down
13 changes: 8 additions & 5 deletions starlette/formparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
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):
Expand Down Expand Up @@ -74,7 +77,7 @@ def on_end(self) -> None:

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,
Expand Down Expand Up @@ -220,7 +223,7 @@ async def parse(self) -> FormData:
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,
Expand Down
4 changes: 2 additions & 2 deletions starlette/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

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:
Expand Down
4 changes: 2 additions & 2 deletions starlette/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ async def app(self, scope: Scope, receive: Receive, send: Send) -> None:
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)

Expand All @@ -782,7 +782,7 @@ def add_route(
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,
Expand Down
2 changes: 1 addition & 1 deletion starlette/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try:
import yaml
except ModuleNotFoundError: # pragma: nocover
except ModuleNotFoundError: # pragma: no cover
yaml = None # type: ignore[assignment]


Expand Down
4 changes: 2 additions & 2 deletions starlette/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
# 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]


Expand Down
2 changes: 1 addition & 1 deletion tests/middleware/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def app(scope: Scope, receive: Receive, send: Send) -> 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:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -281,23 +281,23 @@ 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()
assert data == {"authenticated": True, "user": "tomchristie"}

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()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ async def task1() -> 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()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -795,7 +795,7 @@ async def _send(message: Message) -> None:

with pytest.raises(RuntimeError):
with test_client_factory(app):
pass # pragma: nocover
pass # pragma: no cover
assert startup_failed


Expand All @@ -808,7 +808,7 @@ def run_shutdown() -> 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:
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None:
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:
Expand All @@ -540,7 +540,7 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None:
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:
Expand All @@ -551,7 +551,7 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None:
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:
Expand All @@ -573,7 +573,7 @@ async def app(scope: Scope, receive: Receive, send: Send) -> 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:
Expand Down

0 comments on commit 1a6018e

Please sign in to comment.