Skip to content

Commit

Permalink
replace or operator with Union to be Python 3.8 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
brainelectronics committed Oct 2, 2024
1 parent fabef19 commit bd85042
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions .snippets/14.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
4 changes: 2 additions & 2 deletions snippets2changelog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions snippets2changelog/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion snippets2changelog/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit bd85042

Please sign in to comment.