|
11 | 11 | import sys |
12 | 12 | import time |
13 | 13 | import warnings |
| 14 | +from collections.abc import Iterable |
14 | 15 | from io import StringIO |
15 | 16 | # TODO: py3.10: typing.Optional, typing.Union -> '|' operator |
16 | | -from typing import Any, NamedTuple, Optional |
| 17 | +from typing import Any, NamedTuple, Optional, Union |
17 | 18 |
|
18 | 19 | from filelock import FileLock, Timeout |
19 | 20 | from ruamel.yaml import YAML, scalarstring |
@@ -118,7 +119,11 @@ def pluralize(singular=None): |
118 | 119 | return plural |
119 | 120 |
|
120 | 121 |
|
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: |
122 | 127 | """ |
123 | 128 | Convert an iterable into a nice, human readable list or description:: |
124 | 129 |
|
@@ -189,7 +194,7 @@ def split(values, separator=re.compile("[ ,]+")): |
189 | 194 | return sum([separator.split(value) for value in values], []) |
190 | 195 |
|
191 | 196 |
|
192 | | -def info(message, newline=True): |
| 197 | +def info(message: str, newline: bool = True) -> None: |
193 | 198 | """ Log provided info message to the standard error output """ |
194 | 199 | sys.stderr.write(message + ("\n" if newline else "")) |
195 | 200 |
|
@@ -454,7 +459,9 @@ def get(self): |
454 | 459 | # Coloring |
455 | 460 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
456 | 461 |
|
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"): |
458 | 465 | """ |
459 | 466 | Return text in desired color if coloring enabled |
460 | 467 |
|
@@ -553,7 +560,7 @@ def enabled(self): |
553 | 560 | # Cache directory |
554 | 561 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
555 | 562 |
|
556 | | -def get_cache_directory(create=True): |
| 563 | +def get_cache_directory(create: bool = True) -> str: |
557 | 564 | """ |
558 | 565 | Return cache directory, created by this call if necessary |
559 | 566 |
|
@@ -593,7 +600,7 @@ def set_cache_expiration(seconds): |
593 | 600 | CACHE_EXPIRATION = int(seconds) |
594 | 601 |
|
595 | 602 |
|
596 | | -def clean_cache_directory(): |
| 603 | +def clean_cache_directory() -> None: |
597 | 604 | """ Delete used cache directory if it exists """ |
598 | 605 | cache = get_cache_directory(create=False) |
599 | 606 | if os.path.isdir(cache): |
|
0 commit comments