diff --git a/.snippets/14.md b/.snippets/14.md index 3188bcd..15dab84 100644 --- a/.snippets/14.md +++ b/.snippets/14.md @@ -8,3 +8,4 @@ affected: all - to be compatible as speficied in `pyproject.toml` classifier list - add Python matrix to test workflow with Python versions `['3.8', '3.9', '3.10', '3.11']` - use `actions/checkout` with version `v4` +- use Python 3.8 compatible typing, replace `|` with `Union` diff --git a/snippets2changelog/cli.py b/snippets2changelog/cli.py index ec433be..da50759 100755 --- a/snippets2changelog/cli.py +++ b/snippets2changelog/cli.py @@ -9,7 +9,7 @@ from argparse import Namespace as Args from pathlib import Path from sys import stdout -from typing import Sequence +from typing import Sequence, Union from .common import LOG_LEVELS, collect_user_choice from .creator import ChangelogCreator, SnippetCreator @@ -32,7 +32,7 @@ def does_exist(parser: ArgumentParser, arg: str) -> Path: return Path(arg) -def parse_args(argv: Sequence[str] | None = None) -> Args: +def parse_args(argv: Union[Sequence[str], None] = None) -> Args: """Multi command argument parser""" parser = ArgumentParser(__doc__) parser.add_argument( diff --git a/snippets2changelog/common.py b/snippets2changelog/common.py index 73baa7c..5c13192 100644 --- a/snippets2changelog/common.py +++ b/snippets2changelog/common.py @@ -4,7 +4,7 @@ import json import logging from pathlib import Path -from typing import Any, Dict, List +from typing import Any, Dict, List, Union import yaml @@ -27,7 +27,7 @@ def collect_user_choice(question: str, options: List[str]) -> str: print(f"Invalid input: '{choice}', choose from: {options}") -def read_file(path: Path, parse: str = "read", mode: str = "r") -> Dict[Any, Any] | str | List[str] | Any: +def read_file(path: Path, parse: str = "read", mode: str = "r") -> Union[Dict[Any, Any], str, List[str], Any]: with open(path, mode) as file: if parse == "read": return file.read() @@ -46,7 +46,7 @@ def read_file(path: Path, parse: str = "read", mode: str = "r") -> Dict[Any, Any ) -def save_file(content: str | Dict[Any, Any], path: Path, mode: str = "w", render: str = "txt") -> None: +def save_file(content: Union[str, Dict[Any, Any]], path: Path, mode: str = "w", render: str = "txt") -> None: """ Save a file to the specified path with the given content. diff --git a/snippets2changelog/parser.py b/snippets2changelog/parser.py index 6421343..3ee3779 100644 --- a/snippets2changelog/parser.py +++ b/snippets2changelog/parser.py @@ -20,7 +20,7 @@ class SnippetParserError(Exception): class SnippetParser(object): """docstring for SnippetCreator""" - def __init__(self, additional_keys: tuple[str] | tuple[()] = (), verbosity: int = 0) -> None: + def __init__(self, additional_keys: Union[tuple[str], tuple[()]] = (), verbosity: int = 0) -> None: self._file_name = Path() self._required_parser_keys = ("type", "scope", "affected") + additional_keys self._parsed_content = dict(zip(self._required_parser_keys, [""] * len(self._required_parser_keys)))