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

Enable a few more Python linting rules #2590

Merged
merged 2 commits into from
Aug 22, 2024
Merged
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
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
Loading