From 870c9f3c42bf4d68ddde0bc4e711395e9e3a331d Mon Sep 17 00:00:00 2001 From: andreymal Date: Sun, 10 Sep 2023 21:57:41 +0300 Subject: [PATCH] Lint fixes --- mini_fiction/logic/tags/private.py | 6 +++--- mini_fiction/logic/tags/public.py | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mini_fiction/logic/tags/private.py b/mini_fiction/logic/tags/private.py index 6b7b8a06..ae98f0ee 100644 --- a/mini_fiction/logic/tags/private.py +++ b/mini_fiction/logic/tags/private.py @@ -3,9 +3,9 @@ from dataclasses import dataclass from datetime import datetime from itertools import chain, islice -from typing import List, Optional, Tuple +from typing import List, Optional, Tuple, Union -from flask_babel import lazy_gettext +from flask_babel import LazyString, lazy_gettext from pony import orm from mini_fiction.logic.adminlog import log_changed_fields, log_changed_generic @@ -179,7 +179,7 @@ def set_blacklist(tag: Tag, user: Optional[Author], reason: Optional[str]) -> No log_changed_generic(by=user, what=tag, message=log_message) -def validate_tag_name(raw_tag_name: str) -> Optional[str]: +def validate_tag_name(raw_tag_name: str) -> Optional[Union[str, LazyString]]: iname = normalize_tag(raw_tag_name) if not iname: return lazy_gettext("Empty tag") diff --git a/mini_fiction/logic/tags/public.py b/mini_fiction/logic/tags/public.py index 6bb39398..2ef076b9 100644 --- a/mini_fiction/logic/tags/public.py +++ b/mini_fiction/logic/tags/public.py @@ -3,7 +3,7 @@ from operator import attrgetter from typing import Collection, Dict, List, Literal, Optional, Tuple, Union -from flask_babel import lazy_gettext +from flask_babel import LazyString, lazy_gettext from pony.orm import desc from mini_fiction.logic.adminlog import log_addition, log_changed_fields, log_deletion @@ -52,7 +52,7 @@ class TagsResponse: """Aliased tags that were replaced with canonical ones""" blacklisted: List[Tag] """Blocked tags""" - invalid: List[Tuple[str, str]] + invalid: List[Tuple[str, Union[str, LazyString]]] """List of invalid tags alongside with reasons""" created: List[Tag] """Created tags, if specified to do so""" @@ -76,8 +76,8 @@ def get_tags_objects( tags_db = {x.iname: x for x in tags if isinstance(x, Tag)} # Ищем недостающие теги в базе - inames = [normalize_tag(x) for x in tags_search] - inames = [x for x in inames if x] + inames_opt = [normalize_tag(x) for x in tags_search] + inames = [x for x in inames_opt if x] if inames: # Алгоритм сравнения строк в БД может отличаться от такового в Python, # из-за чего при запросе всех тегов одним запросом будет проблематично @@ -177,12 +177,12 @@ def get_tags_objects( def get_all_tags(*, sort: TagsSortType) -> List[Tag]: - field, reverse = TAG_SORTING[sort] + sorting_field, reverse = TAG_SORTING[sort] return sorted( Tag.select() .filter(lambda x: not x.is_blacklisted and not x.is_alias) .prefetch(Tag.category), - key=attrgetter(field), + key=attrgetter(sorting_field), reverse=reverse, )