Skip to content

Commit

Permalink
Replace typing.Union
Browse files Browse the repository at this point in the history
  • Loading branch information
yaph committed Nov 5, 2024
1 parent 93acae2 commit e0b1f88
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions logya/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from datetime import datetime
from operator import itemgetter
from pathlib import Path
from typing import Union

from markdown import markdown

Expand Down Expand Up @@ -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'}:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions logya/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit e0b1f88

Please sign in to comment.