diff --git a/fmf/utils.py b/fmf/utils.py index 7bc13faf..2d69ad31 100644 --- a/fmf/utils.py +++ b/fmf/utils.py @@ -11,9 +11,10 @@ import sys import time import warnings +from collections.abc import Iterable from io import StringIO # TODO: py3.10: typing.Optional, typing.Union -> '|' operator -from typing import Any, NamedTuple, Optional +from typing import Any, NamedTuple, Optional, Union from filelock import FileLock, Timeout from ruamel.yaml import YAML, scalarstring @@ -118,7 +119,11 @@ def pluralize(singular=None): return plural -def listed(items, singular=None, plural=None, max=None, quote="", join="and"): +def listed(items: Union[int, Iterable[int]], + singular: Optional[str] = None, + plural: Optional[str] = None, + max: Optional[str] = None, + quote: str = "", join: str = "and") -> str: """ Convert an iterable into a nice, human readable list or description:: @@ -189,7 +194,7 @@ def split(values, separator=re.compile("[ ,]+")): return sum([separator.split(value) for value in values], []) -def info(message, newline=True): +def info(message: str, newline: bool = True) -> None: """ Log provided info message to the standard error output """ sys.stderr.write(message + ("\n" if newline else "")) @@ -454,7 +459,9 @@ def get(self): # Coloring # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def color(text, color=None, background=None, light=False, enabled="auto"): +def color(text: str, color: Optional[str] = None, + background: Optional[str] = None, + light: Optional[str] = False, enabled: str = "auto"): """ Return text in desired color if coloring enabled @@ -553,7 +560,7 @@ def enabled(self): # Cache directory # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def get_cache_directory(create=True): +def get_cache_directory(create: bool = True) -> str: """ Return cache directory, created by this call if necessary @@ -593,7 +600,7 @@ def set_cache_expiration(seconds): CACHE_EXPIRATION = int(seconds) -def clean_cache_directory(): +def clean_cache_directory() -> None: """ Delete used cache directory if it exists """ cache = get_cache_directory(create=False) if os.path.isdir(cache):