Hand-fixed typing extra () and changed some formatting to f-strings that Ruff had missed

This commit is contained in:
L. Kärkkäinen 2023-10-25 02:36:08 +00:00 committed by GitHub
parent 6fac60c6fe
commit cdc5dd6b75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 28 additions and 29 deletions

View File

@ -118,7 +118,7 @@ class Blueprint(BaseSanic):
name: str, name: str,
url_prefix: str | None = None, url_prefix: str | None = None,
host: list[str] | str | None = None, host: list[str] | str | None = None,
version: int | (str | float) | None = None, version: int | str | float | None = None,
strict_slashes: bool | None = None, strict_slashes: bool | None = None,
version_prefix: str = "/v", version_prefix: str = "/v",
): ):
@ -203,7 +203,7 @@ class Blueprint(BaseSanic):
self, self,
name: str, name: str,
url_prefix: str | Default | None = _default, url_prefix: str | Default | None = _default,
version: int | (str | (float | Default)) | None = _default, version: int | str | float | Default | None = _default,
version_prefix: str | Default = _default, version_prefix: str | Default = _default,
allow_route_overwrite: bool | Default = _default, allow_route_overwrite: bool | Default = _default,
strict_slashes: bool | Default | None = _default, strict_slashes: bool | Default | None = _default,
@ -273,7 +273,7 @@ class Blueprint(BaseSanic):
def group( def group(
*blueprints: Blueprint | BlueprintGroup, *blueprints: Blueprint | BlueprintGroup,
url_prefix: str | None = None, url_prefix: str | None = None,
version: int | (str | float) | None = None, version: int | str | float | None = None,
strict_slashes: bool | None = None, strict_slashes: bool | None = None,
version_prefix: str = "/v", version_prefix: str = "/v",
name_prefix: str | None = "", name_prefix: str | None = "",
@ -675,7 +675,7 @@ class BlueprintGroup(bpg_base):
self._name_prefix = name_prefix self._name_prefix = name_prefix
@property @property
def url_prefix(self) -> int | (str | float) | None: def url_prefix(self) -> int | str | float | None:
"""The URL prefix for the Blueprint Group. """The URL prefix for the Blueprint Group.
Returns: Returns:
@ -695,7 +695,7 @@ class BlueprintGroup(bpg_base):
return self._blueprints return self._blueprints
@property @property
def version(self) -> str | (int | float) | None: def version(self) -> str | int | float | None:
"""API Version for the Blueprint Group, if any. """API Version for the Blueprint Group, if any.
Returns: Returns:

View File

@ -98,14 +98,14 @@ class Config(dict, metaclass=DescriptorMeta):
INSPECTOR: bool INSPECTOR: bool
INSPECTOR_HOST: str INSPECTOR_HOST: str
INSPECTOR_PORT: int INSPECTOR_PORT: int
INSPECTOR_TLS_KEY: Path | (str | Default) INSPECTOR_TLS_KEY: Path | str | Default
INSPECTOR_TLS_CERT: Path | (str | Default) INSPECTOR_TLS_CERT: Path | str | Default
INSPECTOR_API_KEY: str INSPECTOR_API_KEY: str
KEEP_ALIVE_TIMEOUT: int KEEP_ALIVE_TIMEOUT: int
KEEP_ALIVE: bool KEEP_ALIVE: bool
LOCAL_CERT_CREATOR: str | LocalCertCreator LOCAL_CERT_CREATOR: str | LocalCertCreator
LOCAL_TLS_KEY: Path | (str | Default) LOCAL_TLS_KEY: Path | str | Default
LOCAL_TLS_CERT: Path | (str | Default) LOCAL_TLS_CERT: Path | str | Default
LOCALHOST: str LOCALHOST: str
MOTD: bool MOTD: bool
MOTD_DISPLAY: dict[str, str] MOTD_DISPLAY: dict[str, str]
@ -323,7 +323,7 @@ class Config(dict, metaclass=DescriptorMeta):
except ValueError: except ValueError:
pass pass
def update_config(self, config: bytes | (str | (dict | Any))): def update_config(self, config: bytes | str | dict | Any):
"""Update app.config. """Update app.config.
.. note:: .. note::

View File

@ -529,7 +529,7 @@ def format_http1_response(status: int, headers: HeaderBytesIterable) -> bytes:
def parse_credentials( def parse_credentials(
header: str | None, header: str | None,
prefixes: list | (tuple | set) | None = None, prefixes: list | tuple | set | None = None,
) -> tuple[str | None, str | None]: ) -> tuple[str | None, str | None]:
"""Parses any header with the aim to retrieve any credentials from it. """Parses any header with the aim to retrieve any credentials from it.

View File

@ -55,7 +55,7 @@ def shorthand_to_ctx(
def process_to_context( def process_to_context(
ssldef: None | (ssl.SSLContext | (dict | (str | (list | tuple)))) ssldef: None | ssl.SSLContext | dict | str | list | tuple
) -> ssl.SSLContext | None: ) -> ssl.SSLContext | None:
"""Process app.run ssl argument from easy formats to full SSLContext.""" """Process app.run ssl argument from easy formats to full SSLContext."""
return ( return (

View File

@ -157,7 +157,7 @@ class StartupMixin(metaclass=SanicMeta):
debug: bool = False, debug: bool = False,
auto_reload: bool | None = None, auto_reload: bool | None = None,
version: HTTPVersion = HTTP.VERSION_1, version: HTTPVersion = HTTP.VERSION_1,
ssl: None | (SSLContext | (dict | (str | (list | tuple)))) = None, ssl: None | SSLContext | dict | str | list | tuple = None,
sock: socket | None = None, sock: socket | None = None,
workers: int = 1, workers: int = 1,
protocol: type[Protocol] | None = None, protocol: type[Protocol] | None = None,
@ -287,7 +287,7 @@ class StartupMixin(metaclass=SanicMeta):
debug: bool = False, debug: bool = False,
auto_reload: bool | None = None, auto_reload: bool | None = None,
version: HTTPVersion = HTTP.VERSION_1, version: HTTPVersion = HTTP.VERSION_1,
ssl: None | (SSLContext | (dict | (str | (list | tuple)))) = None, ssl: None | SSLContext | dict | str | list | tuple = None,
sock: socket | None = None, sock: socket | None = None,
workers: int = 1, workers: int = 1,
protocol: type[Protocol] | None = None, protocol: type[Protocol] | None = None,
@ -466,7 +466,7 @@ class StartupMixin(metaclass=SanicMeta):
port: int | None = None, port: int | None = None,
*, *,
debug: bool = False, debug: bool = False,
ssl: None | (SSLContext | (dict | (str | (list | tuple)))) = None, ssl: None | SSLContext | dict | str | list | tuple = None,
sock: socket | None = None, sock: socket | None = None,
protocol: type[Protocol] | None = None, protocol: type[Protocol] | None = None,
backlog: int = 100, backlog: int = 100,
@ -632,7 +632,7 @@ class StartupMixin(metaclass=SanicMeta):
port: int | None = None, port: int | None = None,
debug: bool = False, debug: bool = False,
version: HTTPVersion = HTTP.VERSION_1, version: HTTPVersion = HTTP.VERSION_1,
ssl: None | (SSLContext | (dict | (str | (list | tuple)))) = None, ssl: None | SSLContext | dict | str | list | tuple = None,
sock: socket | None = None, sock: socket | None = None,
unix: str | None = None, unix: str | None = None,
workers: int = 1, workers: int = 1,

View File

@ -6,7 +6,7 @@ from typing import Any
class RequestParameters(dict): class RequestParameters(dict):
"""Hosts a dict with lists as values where get returns the first value of the list and getlist returns the whole shebang""" # noqa: E501 """Hosts a dict with lists as values where get returns the first value of the list and getlist returns the whole shebang""" # noqa: E501
def get(self, name: str, default: Any | None = None) -> Any | None: def get(self, name: str, default: Any = None) -> Any:
"""Return the first value, either the default or actual """Return the first value, either the default or actual
Args: Args:
@ -18,7 +18,7 @@ class RequestParameters(dict):
""" # noqa: E501 """ # noqa: E501
return super().get(name, [default])[0] return super().get(name, [default])[0]
def getlist(self, name: str, default: Any | None = None) -> Any | None: def getlist(self, name: str, default: Any = None) -> Any:
"""Return the entire list """Return the entire list
Args: Args:

View File

@ -155,7 +155,7 @@ class Request(Generic[sanic_type, ctx_type]):
except HttpParserInvalidURLError: except HttpParserInvalidURLError:
url = url_bytes.decode(errors="backslashreplace") url = url_bytes.decode(errors="backslashreplace")
raise BadURL(f"Bad URL: {url}") raise BadURL(f"Bad URL: {url}")
self._id: uuid.UUID | (str | int) | None = None self._id: uuid.UUID | str | int | None = None
self._name: str | None = None self._name: str | None = None
self._stream_id = stream_id self._stream_id = stream_id
self.app = app self.app = app
@ -245,7 +245,7 @@ class Request(Generic[sanic_type, ctx_type]):
return request return request
@classmethod @classmethod
def generate_id(*_) -> uuid.UUID | (str | int): def generate_id(*_) -> uuid.UUID | str | int:
"""Generate a unique ID for the request. """Generate a unique ID for the request.
This method is called to generate a unique ID for each request. This method is called to generate a unique ID for each request.
@ -488,7 +488,7 @@ class Request(Generic[sanic_type, ctx_type]):
return bytes(reqline) return bytes(reqline)
@property @property
def id(self) -> uuid.UUID | (str | int) | None: def id(self) -> uuid.UUID | str | int | None:
"""A request ID passed from the client, or generated from the backend. """A request ID passed from the client, or generated from the backend.
By default, this will look in a request header defined at: By default, this will look in a request header defined at:

View File

@ -120,7 +120,7 @@ def raw(
def html( def html(
body: str | (bytes | HTMLProtocol), body: str | bytes | HTMLProtocol,
status: int = 200, status: int = 200,
headers: dict[str, str] | None = None, headers: dict[str, str] | None = None,
) -> HTTPResponse: ) -> HTTPResponse:
@ -151,7 +151,7 @@ def html(
async def validate_file( async def validate_file(
request_headers: Header, last_modified: datetime | (float | int) request_headers: Header, last_modified: datetime | float | int
) -> HTTPResponse | None: ) -> HTTPResponse | None:
"""Validate file based on request headers. """Validate file based on request headers.
@ -170,8 +170,7 @@ async def validate_file(
if_modified_since = parsedate_to_datetime(if_modified_since) if_modified_since = parsedate_to_datetime(if_modified_since)
except (TypeError, ValueError): except (TypeError, ValueError):
logger.warning( logger.warning(
"Ignoring invalid If-Modified-Since header received: '%s'", f"Ignoring invalid If-Modified-Since header received: '{if_modified_since}'"
if_modified_since,
) )
return None return None
if not isinstance(last_modified, datetime): if not isinstance(last_modified, datetime):
@ -211,7 +210,7 @@ async def file(
mime_type: str | None = None, mime_type: str | None = None,
headers: dict[str, str] | None = None, headers: dict[str, str] | None = None,
filename: str | None = None, filename: str | None = None,
last_modified: datetime | (float | (int | Default)) | None = _default, last_modified: datetime | float | int | Default | None = _default,
max_age: float | int | None = None, max_age: float | int | None = None,
no_store: bool | None = None, no_store: bool | None = None,
_range: Range | None = None, _range: Range | None = None,

View File

@ -64,7 +64,7 @@ class BaseHTTPResponse:
self.asgi: bool = False self.asgi: bool = False
self.body: bytes | None = None self.body: bytes | None = None
self.content_type: str | None = None self.content_type: str | None = None
self.stream: Http | (ASGIApp | HTTPReceiver) | None = None self.stream: Http | ASGIApp | HTTPReceiver | None = None
self.status: int = None self.status: int = None
self.headers = Header({}) self.headers = Header({})
self._cookies: CookieJar | None = None self._cookies: CookieJar | None = None

View File

@ -82,7 +82,7 @@ class Router(BaseRouter):
strict_slashes: bool = False, strict_slashes: bool = False,
stream: bool = False, stream: bool = False,
ignore_body: bool = False, ignore_body: bool = False,
version: str | (float | int) | None = None, version: str | float | int | None = None,
name: str | None = None, name: str | None = None,
unquote: bool = False, unquote: bool = False,
static: bool = False, static: bool = False,

View File

@ -128,4 +128,4 @@ def load_module_from_file_location(
try: try:
return import_string(location) return import_string(location)
except ValueError: except ValueError:
raise OSError("Unable to load configuration %s" % str(location)) raise OSError(f"Unable to load configuration {location!s}")