Skip to content

Commit

Permalink
Merge pull request #2590 from cloudflare/hoodmane/python-lint-2
Browse files Browse the repository at this point in the history
Enable a few more Python linting rules
  • Loading branch information
hoodmane authored Aug 22, 2024
2 parents 1c80e1b + 3b74be6 commit 67b10fb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ select = [
"E", # pycodestyles
"W", # pycodestyles
"F", # pyflakes
"FURB", # refurb
"I", # isort
"PERF", # Perflint
"PGH", # pygrep-hooks
"PLC", # pylint conventions
"PLE", # pylint errors
"PLR", # pylint refactor
"PTH", # Use pathlib
"RUF", # Ruff rules
"TRY", # Exception related lints
"UP", # pyupgrade
]
ignore = [
"E402", # module import not at top of file
"PLR2004", # Magic value used in comparison
"TRY003", # Avoid specifying long messages outside the exception class
"UP038", # Use X | Y in isinstance check instead of (X, Y)
]

Expand Down
13 changes: 11 additions & 2 deletions src/pyodide/internal/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
ASGI = {"spec_version": "2.0", "version": "3.0"}


background_tasks = set()


def run_in_background(coro):
fut = ensure_future(coro)
background_tasks.add(fut)
fut.add_done_callback(background_tasks.discard)


@Depends
async def env(request: Request):
return request.scope["env"]
Expand Down Expand Up @@ -78,7 +87,7 @@ async def send(got):
print("Application shutdown complete")
raise RuntimeError(f"Unexpected lifespan event {got['type']}")

ensure_future(
run_in_background(
app(
{
"asgi": ASGI,
Expand Down Expand Up @@ -184,7 +193,7 @@ async def ws_receive():
return received

env = {}
ensure_future(app(request_to_scope(req, env, ws=True), ws_receive, ws_send))
run_in_background(app(request_to_scope(req, env, ws=True), ws_receive, ws_send))

return Response.new(None, status=101, webSocket=client)

Expand Down
2 changes: 1 addition & 1 deletion src/pyodide/internal/patches/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def _send_single_request(self, request: Request) -> Response:
await timer.async_start()

if not isinstance(request.stream, AsyncByteStream):
raise RuntimeError(
raise TypeError(
"Attempted to send an sync request with an AsyncClient instance."
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"numpy.random.mtrand",
"tempfile",
"aiohttp.http_websocket",
] + RUST_PACKAGES
*RUST_PACKAGES,
]

# Control number of allowed entropy calls.

Expand Down Expand Up @@ -76,7 +77,7 @@ def get_entropy_import_context(name):
# Initial import needs one entropy call to initialize
# std::collections::HashMap hash seed
return rust_package_context
raise Exception(f"Missing context for {name}")
raise RuntimeError(f"Missing context for {name}")


@contextmanager
Expand Down
3 changes: 2 additions & 1 deletion tools/cross/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from argparse import ArgumentParser, Namespace
from dataclasses import dataclass
from pathlib import Path
from sys import exit
from typing import Callable, Optional

CLANG_FORMAT = os.environ.get("CLANG_FORMAT", "clang-format")
Expand Down Expand Up @@ -80,7 +81,7 @@ def check_clang_format() -> None:
exit(1)
except FileNotFoundError:
# Clang-format is not in the PATH
logging.error("clang-format not found in the PATH")
logging.exception("clang-format not found in the PATH")
exit(1)


Expand Down

0 comments on commit 67b10fb

Please sign in to comment.