Skip to content

Commit

Permalink
More type hints
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Aug 10, 2023
1 parent 7abe753 commit 405aa53
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions fmf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::
Expand Down Expand Up @@ -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 ""))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 405aa53

Please sign in to comment.