Skip to content

Commit 405aa53

Browse files
committed
More type hints
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
1 parent 7abe753 commit 405aa53

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

fmf/utils.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
import sys
1212
import time
1313
import warnings
14+
from collections.abc import Iterable
1415
from io import StringIO
1516
# TODO: py3.10: typing.Optional, typing.Union -> '|' operator
16-
from typing import Any, NamedTuple, Optional
17+
from typing import Any, NamedTuple, Optional, Union
1718

1819
from filelock import FileLock, Timeout
1920
from ruamel.yaml import YAML, scalarstring
@@ -118,7 +119,11 @@ def pluralize(singular=None):
118119
return plural
119120

120121

121-
def listed(items, singular=None, plural=None, max=None, quote="", join="and"):
122+
def listed(items: Union[int, Iterable[int]],
123+
singular: Optional[str] = None,
124+
plural: Optional[str] = None,
125+
max: Optional[str] = None,
126+
quote: str = "", join: str = "and") -> str:
122127
"""
123128
Convert an iterable into a nice, human readable list or description::
124129
@@ -189,7 +194,7 @@ def split(values, separator=re.compile("[ ,]+")):
189194
return sum([separator.split(value) for value in values], [])
190195

191196

192-
def info(message, newline=True):
197+
def info(message: str, newline: bool = True) -> None:
193198
""" Log provided info message to the standard error output """
194199
sys.stderr.write(message + ("\n" if newline else ""))
195200

@@ -454,7 +459,9 @@ def get(self):
454459
# Coloring
455460
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
456461

457-
def color(text, color=None, background=None, light=False, enabled="auto"):
462+
def color(text: str, color: Optional[str] = None,
463+
background: Optional[str] = None,
464+
light: Optional[str] = False, enabled: str = "auto"):
458465
"""
459466
Return text in desired color if coloring enabled
460467
@@ -553,7 +560,7 @@ def enabled(self):
553560
# Cache directory
554561
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
555562

556-
def get_cache_directory(create=True):
563+
def get_cache_directory(create: bool = True) -> str:
557564
"""
558565
Return cache directory, created by this call if necessary
559566
@@ -593,7 +600,7 @@ def set_cache_expiration(seconds):
593600
CACHE_EXPIRATION = int(seconds)
594601

595602

596-
def clean_cache_directory():
603+
def clean_cache_directory() -> None:
597604
""" Delete used cache directory if it exists """
598605
cache = get_cache_directory(create=False)
599606
if os.path.isdir(cache):

0 commit comments

Comments
 (0)