diff --git a/sanic/cli/app.py b/sanic/cli/app.py index 929b5cce5b..f6feb5fbd4 100644 --- a/sanic/cli/app.py +++ b/sanic/cli/app.py @@ -282,7 +282,7 @@ def _inspector(self): key, value = arg.split("=") key = key.lstrip("-") except ValueError: - value = False if arg.startswith("--no-") else True + value = not arg.startswith("--no-") key = ( arg.replace("--no-", "") .lstrip("-") diff --git a/sanic/compat.py b/sanic/compat.py index f608909b64..a63c3bcd0f 100644 --- a/sanic/compat.py +++ b/sanic/compat.py @@ -131,6 +131,7 @@ def get_all(self, key: str): use_trio = sys.argv[0].endswith("hypercorn") and "trio" in sys.argv +CancelledErrors: tuple[type[BaseException], ...] if use_trio: # pragma: no cover import trio # type: ignore @@ -139,7 +140,7 @@ def stat_async(path) -> Awaitable[os.stat_result]: return trio.Path(path).stat() open_async = trio.open_file - CancelledErrors = tuple([asyncio.CancelledError, trio.Cancelled]) + CancelledErrors = (asyncio.CancelledError, trio.Cancelled) else: if PYPY_IMPLEMENTATION: pypy_os_module_patch() @@ -153,7 +154,7 @@ def stat_async(path) -> Awaitable[os.stat_result]: async def open_async(file, mode="r", **kwargs): return aio_open(file, mode, **kwargs) - CancelledErrors = tuple([asyncio.CancelledError]) + CancelledErrors = (asyncio.CancelledError,) def ctrlc_workaround_for_windows(app): diff --git a/sanic/server/websockets/impl.py b/sanic/server/websockets/impl.py index d68110773b..3d80be2d42 100644 --- a/sanic/server/websockets/impl.py +++ b/sanic/server/websockets/impl.py @@ -860,7 +860,7 @@ def connection_lost(self, exc): """ The WebSocket Connection is Closed. """ - if not self.ws_proto.state == CLOSED: + if self.ws_proto.state != CLOSED: # signal to the websocket connection handler # we've lost the connection self.ws_proto.fail(code=1006) diff --git a/sanic/worker/process.py b/sanic/worker/process.py index 6d52c92576..68c98ac948 100644 --- a/sanic/worker/process.py +++ b/sanic/worker/process.py @@ -231,12 +231,10 @@ def _wait_to_terminate(self): def _add_config(self) -> bool: sig = signature(self.target) - if "config" in sig.parameters or any( + return "config" in sig.parameters or any( param.kind == param.VAR_KEYWORD for param in sig.parameters.values() - ): - return True - return False + ) class Worker: