Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip magic trailing comma #2496

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ select = ["E", "F", "I"]

[tool.ruff.lint.isort]
combine-as-imports = true
split-on-trailing-comma = false

[tool.ruff.format]
skip-magic-trailing-comma = true

[tool.mypy]
strict = true
Expand Down
5 changes: 1 addition & 4 deletions starlette/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ class Address(typing.NamedTuple):

class URL:
def __init__(
self,
url: str = "",
scope: Scope | None = None,
**components: typing.Any,
self, url: str = "", scope: Scope | None = None, **components: typing.Any
) -> None:
if scope is not None:
assert not url, 'Cannot set both "url" and "scope".'
Expand Down
5 changes: 1 addition & 4 deletions starlette/middleware/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:

class Middleware:
def __init__(
self,
cls: type[_MiddlewareClass[P]],
*args: P.args,
**kwargs: P.kwargs,
self, cls: type[_MiddlewareClass[P]], *args: P.args, **kwargs: P.kwargs
) -> None:
self.cls = cls
self.args = args
Expand Down
12 changes: 2 additions & 10 deletions starlette/middleware/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,13 @@ async def wrapped_receive(self) -> Message:
if getattr(self, "_body", None) is not None:
# body() was called, we return it even if the client disconnected
self._wrapped_rcv_consumed = True
return {
"type": "http.request",
"body": self._body,
"more_body": False,
}
return {"type": "http.request", "body": self._body, "more_body": False}
elif self._stream_consumed:
# stream() was called to completion
# return an empty body so that downstream apps don't hang
# waiting for a disconnect
self._wrapped_rcv_consumed = True
return {
"type": "http.request",
"body": b"",
"more_body": False,
}
return {"type": "http.request", "body": b"", "more_body": False}
else:
# body() was never called and stream() wasn't consumed
try:
Expand Down
8 changes: 2 additions & 6 deletions starlette/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,18 +659,14 @@ def __init__(
"use an @contextlib.asynccontextmanager function instead",
DeprecationWarning,
)
self.lifespan_context = asynccontextmanager(
lifespan,
)
self.lifespan_context = asynccontextmanager(lifespan)
elif inspect.isgeneratorfunction(lifespan):
warnings.warn(
"generator function lifespans are deprecated, "
"use an @contextlib.asynccontextmanager function instead",
DeprecationWarning,
)
self.lifespan_context = _wrap_gen_lifespan_context(
lifespan,
)
self.lifespan_context = _wrap_gen_lifespan_context(lifespan)
else:
self.lifespan_context = lifespan

Expand Down
5 changes: 1 addition & 4 deletions starlette/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
await send(
{
"type": "http.response.debug",
"info": {
"template": self.template,
"context": self.context,
},
"info": {"template": self.template, "context": self.context},
}
)
await super().__call__(scope, receive, send)
Expand Down
18 changes: 4 additions & 14 deletions starlette/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def __init__(self, session: WebSocketTestSession) -> None:


class WebSocketDenialResponse( # type: ignore[misc]
httpx.Response,
WebSocketDisconnect,
httpx.Response, WebSocketDisconnect
):
"""
A special case of `WebSocketDisconnect`, raised in the `TestClient` if the
Expand All @@ -90,10 +89,7 @@ class WebSocketDenialResponse( # type: ignore[misc]

class WebSocketTestSession:
def __init__(
self,
app: ASGI3App,
scope: Scope,
portal_factory: _PortalFactoryType,
self, app: ASGI3App, scope: Scope, portal_factory: _PortalFactoryType
) -> None:
self.app = app
self.scope = scope
Expand Down Expand Up @@ -182,9 +178,7 @@ def _raise_on_close(self, message: Message) -> None:
if not message.get("more_body", False):
break
raise WebSocketDenialResponse(
status_code=status_code,
headers=headers,
content=b"".join(body),
status_code=status_code, headers=headers, content=b"".join(body)
)

def send(self, message: Message) -> None:
Expand Down Expand Up @@ -400,11 +394,7 @@ async def send(message: Message) -> None:
if self.raise_server_exceptions:
assert response_started, "TestClient did not receive any response."
elif not response_started:
raw_kwargs = {
"status_code": 500,
"headers": [],
"stream": io.BytesIO(),
}
raw_kwargs = {"status_code": 500, "headers": [], "stream": io.BytesIO()}

raw_kwargs["stream"] = httpx.ByteStream(raw_kwargs["stream"].read())

Expand Down
4 changes: 1 addition & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ def test_client_factory(
# anyio_backend_name defined by:
# https://anyio.readthedocs.io/en/stable/testing.html#specifying-the-backends-to-run-on
return functools.partial(
TestClient,
backend=anyio_backend_name,
backend_options=anyio_backend_options,
TestClient, backend=anyio_backend_name, backend_options=anyio_backend_options
)
Loading