Skip to content

Commit

Permalink
Run ruff with some changes (#2932)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins committed Mar 31, 2024
1 parent 1495b64 commit 2c38d57
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 70 deletions.
33 changes: 14 additions & 19 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ def __init__(
inspector: bool = False,
inspector_class: Optional[Type[Inspector]] = None,
certloader_class: Optional[Type[CertLoader]] = None,
) -> None:
...
) -> None: ...

@overload
def __init__(
Expand All @@ -269,8 +268,7 @@ def __init__(
inspector: bool = False,
inspector_class: Optional[Type[Inspector]] = None,
certloader_class: Optional[Type[CertLoader]] = None,
) -> None:
...
) -> None: ...

@overload
def __init__(
Expand All @@ -291,8 +289,7 @@ def __init__(
inspector: bool = False,
inspector_class: Optional[Type[Inspector]] = None,
certloader_class: Optional[Type[CertLoader]] = None,
) -> None:
...
) -> None: ...

@overload
def __init__(
Expand All @@ -313,8 +310,7 @@ def __init__(
inspector: bool = False,
inspector_class: Optional[Type[Inspector]] = None,
certloader_class: Optional[Type[CertLoader]] = None,
) -> None:
...
) -> None: ...

def __init__(
self,
Expand Down Expand Up @@ -380,7 +376,7 @@ def __init__(
self.listeners: Dict[str, List[ListenerType[Any]]] = defaultdict(list)
self.named_request_middleware: Dict[str, Deque[Middleware]] = {}
self.named_response_middleware: Dict[str, Deque[Middleware]] = {}
self.request_class: Type[Request] = request_class or Request
self.request_class = request_class or Request
self.request_middleware: Deque[Middleware] = deque()
self.response_middleware: Deque[Middleware] = deque()
self.router: Router = router or Router()
Expand Down Expand Up @@ -661,8 +657,7 @@ def dispatch(
fail_not_found: bool = True,
inline: Literal[True],
reverse: bool = False,
) -> Coroutine[Any, Any, Awaitable[Any]]:
...
) -> Coroutine[Any, Any, Awaitable[Any]]: ...

@overload
def dispatch(
Expand All @@ -674,8 +669,7 @@ def dispatch(
fail_not_found: bool = True,
inline: Literal[False] = False,
reverse: bool = False,
) -> Coroutine[Any, Any, Awaitable[Task]]:
...
) -> Coroutine[Any, Any, Awaitable[Task]]: ...

def dispatch(
self,
Expand Down Expand Up @@ -1778,18 +1772,19 @@ def add_task(
return None

@overload
def get_task(self, name: str, *, raise_exception: Literal[True]) -> Task:
...
def get_task(
self, name: str, *, raise_exception: Literal[True]
) -> Task: ...

@overload
def get_task(
self, name: str, *, raise_exception: Literal[False]
) -> Optional[Task]:
...
) -> Optional[Task]: ...

@overload
def get_task(self, name: str, *, raise_exception: bool) -> Optional[Task]:
...
def get_task(
self, name: str, *, raise_exception: bool
) -> Optional[Task]: ...

def get_task(
self, name: str, *, raise_exception: bool = True
Expand Down
2 changes: 1 addition & 1 deletion sanic/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def create(
# All servers send them separately
url_bytes = b"%b?%b" % (url_bytes, query)

request_class = sanic_app.request_class or Request
request_class = sanic_app.request_class or Request # type: ignore
instance.request = request_class(
url_bytes,
headers,
Expand Down
18 changes: 6 additions & 12 deletions sanic/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,10 @@ def __iter__(self) -> Iterator[Blueprint]:
return iter(self._blueprints)

@overload
def __getitem__(self, item: int) -> Blueprint:
...
def __getitem__(self, item: int) -> Blueprint: ...

@overload
def __getitem__(self, item: slice) -> MutableSequence[Blueprint]:
...
def __getitem__(self, item: slice) -> MutableSequence[Blueprint]: ...

def __getitem__(
self, item: Union[int, slice]
Expand All @@ -807,12 +805,10 @@ def __getitem__(
return self._blueprints[item]

@overload
def __setitem__(self, index: int, item: Blueprint) -> None:
...
def __setitem__(self, index: int, item: Blueprint) -> None: ...

@overload
def __setitem__(self, index: slice, item: Iterable[Blueprint]) -> None:
...
def __setitem__(self, index: slice, item: Iterable[Blueprint]) -> None: ...

def __setitem__(
self,
Expand Down Expand Up @@ -848,12 +844,10 @@ def __setitem__(
raise TypeError("Index must be int or slice")

@overload
def __delitem__(self, index: int) -> None:
...
def __delitem__(self, index: int) -> None: ...

@overload
def __delitem__(self, index: slice) -> None:
...
def __delitem__(self, index: slice) -> None: ...

def __delitem__(self, index: Union[int, slice]) -> None:
"""Delete the Blueprint object at the specified index.
Expand Down
3 changes: 1 addition & 2 deletions sanic/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def add_bool_arguments(self, *args, nullable=False, **kwargs):
params = {args[0][2:].replace("-", "_"): None}
group.set_defaults(**params)

def prepare(self, args) -> None:
...
def prepare(self, args) -> None: ...


class GeneralGroup(Group):
Expand Down
3 changes: 1 addition & 2 deletions sanic/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def respond(self, response):
response.stream = self
return response

async def send(self, data, end_stream):
...
async def send(self, data, end_stream): ...


class Result(NamedTuple):
Expand Down
2 changes: 1 addition & 1 deletion sanic/cookies/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


COOKIE_NAME_RESERVED_CHARS = re.compile(
'[\x00-\x1F\x7F-\xFF()<>@,;:\\\\"/[\\]?={} \x09]'
'[\x00-\x1f\x7f-\xff()<>@,;:\\\\"/[\\]?={} \x09]'
)
OCTAL_PATTERN = re.compile(r"\\[0-3][0-7][0-7]")
QUOTE_PATTERN = re.compile(r"[\\].")
Expand Down
2 changes: 1 addition & 1 deletion sanic/cookies/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

LEGAL_CHARS = string.ascii_letters + string.digits + "!#$%&'*+-.^_`|~:"
UNESCAPED_CHARS = LEGAL_CHARS + " ()/<=>?@[]{}"
TRANSLATOR = {ch: f"\\{ch:03o}" for ch in bytes(range(32)) + b'";\\\x7F'}
TRANSLATOR = {ch: f"\\{ch:03o}" for ch in bytes(range(32)) + b'";\\\x7f'}


def _quote(str): # no cov
Expand Down
1 change: 1 addition & 0 deletions sanic/errorpages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
will attempt to provide an appropriate response format based upon the
request type.
"""

from __future__ import annotations

import sys
Expand Down
6 changes: 3 additions & 3 deletions sanic/handlers/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def lookup(self, exception, route_name: Optional[str] = None):
exception_key = (ancestor, name)
if exception_key in self.cached_handlers:
handler = self.cached_handlers[exception_key]
self.cached_handlers[
(exception_class, route_name)
] = handler
self.cached_handlers[(exception_class, route_name)] = (
handler
)
return handler

if ancestor is BaseException:
Expand Down
6 changes: 2 additions & 4 deletions sanic/http/http3.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,13 @@ def _send(self, data: bytes, end_stream: bool) -> None:
class WebsocketReceiver(Receiver): # noqa
"""Websocket receiver implementation."""

async def run(self):
...
async def run(self): ...


class WebTransportReceiver(Receiver): # noqa
"""WebTransport receiver implementation."""

async def run(self):
...
async def run(self): ...


class Http3:
Expand Down
6 changes: 2 additions & 4 deletions sanic/mixins/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def listener(
apply: bool = ...,
*,
priority: int = 0,
) -> ListenerType[Sanic]:
...
) -> ListenerType[Sanic]: ...

@overload
def listener(
Expand All @@ -51,8 +50,7 @@ def listener(
apply: bool = ...,
*,
priority: int = 0,
) -> Callable[[ListenerType[Sanic]], ListenerType[Sanic]]:
...
) -> Callable[[ListenerType[Sanic]], ListenerType[Sanic]]: ...

def listener(
self,
Expand Down
6 changes: 2 additions & 4 deletions sanic/mixins/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def middleware(
apply: bool = True,
*,
priority: int = 0,
) -> MiddlewareType:
...
) -> MiddlewareType: ...

@overload
def middleware(
Expand All @@ -37,8 +36,7 @@ def middleware(
apply: bool = True,
*,
priority: int = 0,
) -> Callable[[MiddlewareType], MiddlewareType]:
...
) -> Callable[[MiddlewareType], MiddlewareType]: ...

def middleware(
self,
Expand Down
3 changes: 1 addition & 2 deletions sanic/mixins/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def add_signal(
"""
if not handler:

async def noop(**context):
...
async def noop(**context): ...

handler = noop
self.signal(event=event, condition=condition, exclusive=exclusive)(
Expand Down
3 changes: 1 addition & 2 deletions sanic/models/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ class FutureSignal(NamedTuple):
priority: int


class FutureRegistry(set):
...
class FutureRegistry(set): ...
6 changes: 2 additions & 4 deletions sanic/models/protocol_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
from typing import Protocol

class HTMLProtocol(Protocol):
def __html__(self) -> Union[str, bytes]:
...
def __html__(self) -> Union[str, bytes]: ...

def _repr_html_(self) -> Union[str, bytes]:
...
def _repr_html_(self) -> Union[str, bytes]: ...

class Range(Protocol):
start: Optional[int]
Expand Down
3 changes: 1 addition & 2 deletions sanic/pages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def _foot(self) -> None:
self.doc.div("DEBUG mode")

@abstractmethod
def _body(self) -> None:
...
def _body(self) -> None: ...

def _sanic_logo(self) -> None:
self.doc.a(
Expand Down
6 changes: 3 additions & 3 deletions sanic/response/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ async def file(
if _range:
await f.seek(_range.start)
out_stream = await f.read(_range.size)
headers[
"Content-Range"
] = f"bytes {_range.start}-{_range.end}/{_range.total}"
headers["Content-Range"] = (
f"bytes {_range.start}-{_range.end}/{_range.total}"
)
status = 206
else:
out_stream = await f.read()
Expand Down
3 changes: 1 addition & 2 deletions sanic/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class Event(Enum):
GENERIC_SIGNAL_FORMAT = "__generic__.__signal__.%s"


def _blank():
...
def _blank(): ...


class Signal(Route):
Expand Down
3 changes: 1 addition & 2 deletions sanic/touchup/schemes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def __init__(self, app) -> None:
self.app = app

@abstractmethod
def visitors(self) -> List[NodeTransformer]:
...
def visitors(self) -> List[NodeTransformer]: ...

def __init_subclass__(cls):
BaseScheme._registry.add(cls)
Expand Down

0 comments on commit 2c38d57

Please sign in to comment.