From a65c85300c22e3bcaef72bf67020ab8f8dc68408 Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Tue, 16 Apr 2024 16:33:40 +0200 Subject: [PATCH] Update new code for style compliance --- pelican/tests/test_importer.py | 6 +++--- pelican/utils.py | 26 +++++++++++--------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/pelican/tests/test_importer.py b/pelican/tests/test_importer.py index 7cc10bca..469184cd 100644 --- a/pelican/tests/test_importer.py +++ b/pelican/tests/test_importer.py @@ -19,12 +19,12 @@ from pelican.tools.pelican_import import ( download_attachments, fields2pelican, get_attachments, - tumblr2fields, - wp2fields, + medium_slug, mediumpost2fields, mediumposts2fields, strip_medium_post_content, - medium_slug, + tumblr2fields, + wp2fields, ) from pelican.utils import path_to_file_url, slugify diff --git a/pelican/utils.py b/pelican/utils.py index f4eeb8c4..ce751233 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -23,14 +23,10 @@ from typing import ( Any, Callable, Collection, - Dict, Generator, Iterable, - List, Optional, Sequence, - Tuple, - Type, Union, ) @@ -153,7 +149,7 @@ class memoized: def __init__(self, func: Callable) -> None: self.func = func - self.cache: Dict[Any, Any] = {} + self.cache: dict[Any, Any] = {} def __call__(self, *args) -> Any: if not isinstance(args, Hashable): @@ -180,8 +176,8 @@ class memoized: def deprecated_attribute( old: str, new: str, - since: Tuple[int, ...], - remove: Optional[Tuple[int, ...]] = None, + since: tuple[int, ...], + remove: Optional[tuple[int, ...]] = None, doc: Optional[str] = None, ): """Attribute deprecation decorator for gentle upgrades @@ -251,7 +247,7 @@ def pelican_open( def slugify( value: str, - regex_subs: Iterable[Tuple[str, str]] = (), + regex_subs: Iterable[tuple[str, str]] = (), preserve_case: bool = False, use_unicode: bool = False, ) -> str: @@ -637,9 +633,9 @@ def truncate_html_words(s: str, num: int, end_text: str = "…") -> str: def process_translations( - content_list: List[Content], + content_list: list[Content], translation_id: Optional[Union[str, Collection[str]]] = None, -) -> Tuple[List[Content], List[Content]]: +) -> tuple[list[Content], list[Content]]: """Finds translations and returns them. For each content_list item, populates the 'translations' attribute, and @@ -697,7 +693,7 @@ def process_translations( return index, translations -def get_original_items(items: List[Content], with_str: str) -> List[Content]: +def get_original_items(items: list[Content], with_str: str) -> list[Content]: def _warn_source_paths(msg, items, *extra): args = [len(items)] args.extend(extra) @@ -738,9 +734,9 @@ def get_original_items(items: List[Content], with_str: str) -> List[Content]: def order_content( - content_list: List[Content], + content_list: list[Content], order_by: Union[str, Callable[[Content], Any], None] = "slug", -) -> List[Content]: +) -> list[Content]: """Sorts content. order_by can be a string of an attribute or sorting function. If order_by @@ -802,8 +798,8 @@ def order_content( def wait_for_changes( settings_file: str, - reader_class: Type["Readers"], - settings: "Settings", + reader_class: type[Readers], + settings: Settings, ): content_path = settings.get("PATH", "") theme_path = settings.get("THEME", "")