From a165fec74781afedb94ad4a1ec08cb705d93401e Mon Sep 17 00:00:00 2001 From: Bot <> Date: Fri, 29 Mar 2024 16:00:00 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- an_website/endpoints/endpoints.py | 6 +- an_website/quotes/generator.py | 12 +-- an_website/reporting/reporting.py | 6 +- an_website/search/search.py | 112 +++++++++++------------ an_website/utils/better_config_parser.py | 30 ++++-- an_website/utils/decorators.py | 12 ++- an_website/utils/options.py | 3 +- 7 files changed, 98 insertions(+), 83 deletions(-) diff --git a/an_website/endpoints/endpoints.py b/an_website/endpoints/endpoints.py index d718c4c89..8693329ed 100644 --- a/an_website/endpoints/endpoints.py +++ b/an_website/endpoints/endpoints.py @@ -102,9 +102,9 @@ def get_endpoints( class EndpointsAPI(APIRequestHandler, Endpoints): """Show a list of all API endpoints.""" - POSSIBLE_CONTENT_TYPES: ClassVar[tuple[str, ...]] = ( - APIRequestHandler.POSSIBLE_CONTENT_TYPES + ("application/x-ndjson",) - ) + POSSIBLE_CONTENT_TYPES: ClassVar[ + tuple[str, ...] + ] = APIRequestHandler.POSSIBLE_CONTENT_TYPES + ("application/x-ndjson",) async def get(self, *, head: bool = False) -> None: """Handle a GET request.""" diff --git a/an_website/quotes/generator.py b/an_website/quotes/generator.py index 30b85a04f..b7a2f7437 100644 --- a/an_website/quotes/generator.py +++ b/an_website/quotes/generator.py @@ -42,14 +42,14 @@ def get_authors_and_quotes(count: int) -> tuple[list[Author], list[Quote]]: wrong_quote = get_wrong_quotes(lambda wq: wq.rating > 0, shuffle=True)[0] if wrong_quote.author not in authors: - authors[random.randrange(0, len(authors))] = ( # nosec: B311 - wrong_quote.author - ) + authors[ + random.randrange(0, len(authors)) + ] = wrong_quote.author # nosec: B311 if wrong_quote.quote not in quotes: - quotes[random.randrange(0, len(quotes))] = ( # nosec: B311 - wrong_quote.quote - ) + quotes[ + random.randrange(0, len(quotes)) + ] = wrong_quote.quote # nosec: B311 return authors, quotes diff --git a/an_website/reporting/reporting.py b/an_website/reporting/reporting.py index 72f70bc66..42efcc713 100644 --- a/an_website/reporting/reporting.py +++ b/an_website/reporting/reporting.py @@ -110,9 +110,9 @@ async def get_reports( # pylint: disable=too-many-arguments class ReportingAPI(APIRequestHandler): """The request handler for the Reporting API™️.""" - POSSIBLE_CONTENT_TYPES: ClassVar[tuple[str, ...]] = ( - APIRequestHandler.POSSIBLE_CONTENT_TYPES + ("application/x-ndjson",) - ) + POSSIBLE_CONTENT_TYPES: ClassVar[ + tuple[str, ...] + ] = APIRequestHandler.POSSIBLE_CONTENT_TYPES + ("application/x-ndjson",) RATELIMIT_GET_LIMIT: ClassVar[int] = 20 RATELIMIT_GET_COUNT_PER_PERIOD: ClassVar[int] = 2 diff --git a/an_website/search/search.py b/an_website/search/search.py index 4b1e58005..f396a1d1a 100644 --- a/an_website/search/search.py +++ b/an_website/search/search.py @@ -186,68 +186,68 @@ def search_old_internal(self, query: str) -> list[OldSearchPageInfo]: .map(self.convert_page_info_to_simple_tuple) .map(lambda unscored: search.ScoredValue(1, unscored)) ) - pages: search.DataProvider[PageInfo, UnscoredPageInfo] = ( - search.DataProvider( - self.get_all_page_info, - lambda page_info: ( - page_info.name, - page_info.description, - *page_info.keywords, - ), - self.convert_page_info_to_simple_tuple, - ) + pages: search.DataProvider[ + PageInfo, UnscoredPageInfo + ] = search.DataProvider( + self.get_all_page_info, + lambda page_info: ( + page_info.name, + page_info.description, + *page_info.keywords, + ), + self.convert_page_info_to_simple_tuple, ) - soundboard: search.DataProvider[SoundInfo, UnscoredPageInfo] = ( - search.DataProvider( - ALL_SOUNDS, - lambda sound_info: ( - sound_info.get_text(), - sound_info.person.value, - ), - lambda sound_info: ( - ( - "url", - self.fix_url( - f"/soundboard/{sound_info.person.name}#{sound_info.get_filename()}" - ), + soundboard: search.DataProvider[ + SoundInfo, UnscoredPageInfo + ] = search.DataProvider( + ALL_SOUNDS, + lambda sound_info: ( + sound_info.get_text(), + sound_info.person.value, + ), + lambda sound_info: ( + ( + "url", + self.fix_url( + f"/soundboard/{sound_info.person.name}#{sound_info.get_filename()}" ), - ("title", f"Soundboard ({sound_info.person.value})"), - ("description", sound_info.get_text()), ), - ) + ("title", f"Soundboard ({sound_info.person.value})"), + ("description", sound_info.get_text()), + ), ) - authors: search.DataProvider[Author, UnscoredPageInfo] = ( - search.DataProvider( - get_authors, - lambda author: author.name, - lambda author: ( - ("url", self.fix_url(author.get_path())), - ("title", "Autoren-Info"), - ("description", author.name), - ), - ) + authors: search.DataProvider[ + Author, UnscoredPageInfo + ] = search.DataProvider( + get_authors, + lambda author: author.name, + lambda author: ( + ("url", self.fix_url(author.get_path())), + ("title", "Autoren-Info"), + ("description", author.name), + ), ) - quotes: search.DataProvider[Quote, UnscoredPageInfo] = ( - search.DataProvider( - get_quotes, - lambda quote: (quote.quote, quote.author.name), - lambda q: ( - ("url", self.fix_url(q.get_path())), - ("title", "Zitat-Info"), - ("description", str(q)), - ), - ) + quotes: search.DataProvider[ + Quote, UnscoredPageInfo + ] = search.DataProvider( + get_quotes, + lambda quote: (quote.quote, quote.author.name), + lambda q: ( + ("url", self.fix_url(q.get_path())), + ("title", "Zitat-Info"), + ("description", str(q)), + ), ) - wrong_quotes: search.DataProvider[WrongQuote, UnscoredPageInfo] = ( - search.DataProvider( - lambda: get_wrong_quotes(lambda wq: wq.rating > 0), - lambda wq: (wq.quote.quote, wq.author.name), - lambda wq: ( - ("url", self.fix_url(wq.get_path())), - ("title", "Falsches Zitat"), - ("description", str(wq)), - ), - ) + wrong_quotes: search.DataProvider[ + WrongQuote, UnscoredPageInfo + ] = search.DataProvider( + lambda: get_wrong_quotes(lambda wq: wq.rating > 0), + lambda wq: (wq.quote.quote, wq.author.name), + lambda wq: ( + ("url", self.fix_url(wq.get_path())), + ("title", "Falsches Zitat"), + ("description", str(wq)), + ), ) return search.search( query_object, diff --git a/an_website/utils/better_config_parser.py b/an_website/utils/better_config_parser.py index 618fb6369..084924dee 100644 --- a/an_website/utils/better_config_parser.py +++ b/an_website/utils/better_config_parser.py @@ -132,12 +132,14 @@ def from_path(*path: pathlib.Path) -> BetterConfigParser: @overload # type: ignore[override] def get( # noqa: D102 # pylint: disable=arguments-differ self, section: str, option: str, *, fallback: OptionalStr - ) -> str | OptionalStr: ... + ) -> str | OptionalStr: + ... @overload def get( # pylint: disable=arguments-differ self, section: str, option: str - ) -> str: ... + ) -> str: + ... def get(self, section: str, option: str, **kwargs: Any) -> object: """Get an option in a section.""" @@ -155,12 +157,14 @@ def get(self, section: str, option: str, **kwargs: Any) -> object: @overload # type: ignore[override] def getboolean( # noqa: D102 # pylint: disable=arguments-differ self, section: str, option: str, *, fallback: OptionalBool - ) -> bool | OptionalBool: ... + ) -> bool | OptionalBool: + ... @overload def getboolean( # pylint: disable=arguments-differ self, section: str, option: str - ) -> bool: ... + ) -> bool: + ... def getboolean(self, section: str, option: str, **kwargs: Any) -> object: """Get a boolean option.""" @@ -176,12 +180,14 @@ def getboolean(self, section: str, option: str, **kwargs: Any) -> object: @overload # type: ignore[override] def getfloat( # noqa: D102 # pylint: disable=arguments-differ self, section: str, option: str, *, fallback: OptionalFloat - ) -> float | OptionalFloat: ... + ) -> float | OptionalFloat: + ... @overload def getfloat( # pylint: disable=arguments-differ self, section: str, option: str - ) -> float: ... + ) -> float: + ... def getfloat(self, section: str, option: str, **kwargs: Any) -> object: """Get an int option.""" @@ -195,12 +201,14 @@ def getfloat(self, section: str, option: str, **kwargs: Any) -> object: @overload # type: ignore[override] def getint( # noqa: D102 # pylint: disable=arguments-differ self, section: str, option: str, *, fallback: OptionalInt - ) -> int | OptionalInt: ... + ) -> int | OptionalInt: + ... @overload def getint( # pylint: disable=arguments-differ self, section: str, option: str - ) -> int: ... + ) -> int: + ... def getint(self, section: str, option: str, **kwargs: Any) -> object: """Get an int option.""" @@ -214,10 +222,12 @@ def getint(self, section: str, option: str, **kwargs: Any) -> object: @overload def getset( # noqa: D102 self, section: str, option: str, *, fallback: OptionalSetStr - ) -> set[str] | OptionalSetStr: ... + ) -> set[str] | OptionalSetStr: + ... @overload - def getset(self, section: str, option: str) -> set[str]: ... + def getset(self, section: str, option: str) -> set[str]: + ... def getset(self, section: str, option: str, **kwargs: Any) -> object: """Get an int option.""" diff --git a/an_website/utils/decorators.py b/an_website/utils/decorators.py index c847d8816..053694f77 100644 --- a/an_website/utils/decorators.py +++ b/an_website/utils/decorators.py @@ -111,14 +111,16 @@ def requires( *perms: Permission, return_instead_of_finishing: Default, allow_cookie_auth: bool = True, -) -> Callable[[Callable[Args, Ret]], Callable[Args, Ret | Default]]: ... +) -> Callable[[Callable[Args, Ret]], Callable[Args, Ret | Default]]: + ... @overload def requires( *perms: Permission, allow_cookie_auth: bool = True, -) -> Callable[[Callable[Args, Ret]], Callable[Args, Ret]]: ... +) -> Callable[[Callable[Args, Ret]], Callable[Args, Ret]]: + ... def requires( @@ -171,14 +173,16 @@ def wrapper(*args: Args.args, **kwargs: Args.kwargs) -> Any: def requires_settings( *settings: str, return_: Default, -) -> Callable[[Callable[Args, Ret]], Callable[Args, Ret | Default]]: ... +) -> Callable[[Callable[Args, Ret]], Callable[Args, Ret | Default]]: + ... @overload def requires_settings( *settings: str, status_code: int, -) -> Callable[[Callable[Args, Ret]], Callable[Args, Ret | None]]: ... +) -> Callable[[Callable[Args, Ret]], Callable[Args, Ret | None]]: + ... def requires_settings( diff --git a/an_website/utils/options.py b/an_website/utils/options.py index 9168267fb..5a8841d61 100644 --- a/an_website/utils/options.py +++ b/an_website/utils/options.py @@ -51,7 +51,8 @@ class Option(ABC, Generic[T]): @overload def __get__( # noqa: D105 self, obj: None, _: type[Options] | None = None, / # noqa: W504 - ) -> Option[T]: ... + ) -> Option[T]: + ... @overload def __get__(self, obj: Options, _: type[Options] | None = None, /) -> T: