Skip to content

Commit

Permalink
🤦
Browse files Browse the repository at this point in the history
  • Loading branch information
Bot committed Mar 29, 2024
1 parent d50cf33 commit a165fec
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 83 deletions.
6 changes: 3 additions & 3 deletions an_website/endpoints/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
12 changes: 6 additions & 6 deletions an_website/quotes/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions an_website/reporting/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 56 additions & 56 deletions an_website/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 20 additions & 10 deletions an_website/utils/better_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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."""
Expand All @@ -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."""
Expand All @@ -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."""
Expand All @@ -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."""
Expand Down
12 changes: 8 additions & 4 deletions an_website/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion an_website/utils/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a165fec

Please sign in to comment.