From e0b1f888f74f98d028b7818b7d2c7a5a25dbc12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramiro=20G=C3=B3mez?= Date: Tue, 5 Nov 2024 22:59:39 +0100 Subject: [PATCH] Replace typing.Union --- logya/content.py | 5 ++--- logya/template.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/logya/content.py b/logya/content.py index 54ed3f3..a34cdd6 100644 --- a/logya/content.py +++ b/logya/content.py @@ -2,7 +2,6 @@ from datetime import datetime from operator import itemgetter from pathlib import Path -from typing import Union from markdown import markdown @@ -33,7 +32,7 @@ } -def content_type(path: Path) -> Union[None, str]: +def content_type(path: Path) -> str | None: """Return content type based in file extensions.""" if path.suffix in {'.html', '.htm'}: @@ -87,7 +86,7 @@ def parse(content: str) -> dict: return parsed -def read(path: Path, path_rel: Path, markdown_extensions: list) -> Union[None, dict]: +def read(path: Path, path_rel: Path, markdown_extensions: list) -> dict | None: try: doc = parse(path.read_text().strip()) except Exception as err: diff --git a/logya/template.py b/logya/template.py index 6e1a589..5d34a8d 100644 --- a/logya/template.py +++ b/logya/template.py @@ -3,7 +3,7 @@ from operator import itemgetter from pathlib import Path from string import ascii_lowercase -from typing import Any, Dict, Union +from typing import Any from jinja2 import Environment, FileSystemLoader from markupsafe import escape @@ -26,7 +26,7 @@ def _alpha_index( in `non_ascii_key`. """ - index: Dict[str, list] = {} + index: dict[str, list] = {} for item in items: value = item[sort_attr] @@ -40,7 +40,7 @@ def _alpha_index( return {key: sorted(index[key], key=itemgetter(sort_attr)) for key in keys} -def _filesource(root: Path, name: str, lines: int | None = None, raw: bool = False) -> Union[None, str]: +def _filesource(root: Path, name: str, lines: int | None = None, raw: bool = False) -> str | None: """Read and return source of text files. A template function that reads the source of the given file and returns it. Content is escaped by default so it can