Added optional type hinting

This commit is contained in:
Pete Davison 2021-07-09 10:33:09 +00:00
parent 9564ac5462
commit 74ae964858

View file

@ -13,15 +13,15 @@ See Also:
__all__ = ["decimal"] __all__ = ["decimal"]
from typing import Iterable, List, Tuple from typing import Iterable, List, Tuple, Optional
def _to_str( def _to_str(
size: int, size: int,
suffixes: Iterable[str], suffixes: Iterable[str],
base: int, base: int,
precision: int = 1, precision: Optional[int] = 1,
separator: str = " ", separator: Optional[str] = " ",
) -> str: ) -> str:
if size == 1: if size == 1:
return "1 byte" return "1 byte"
@ -49,7 +49,7 @@ def pick_unit_and_suffix(size: int, suffixes: List[str], base: int) -> Tuple[int
return unit, suffix return unit, suffix
def decimal(size: int, precision: int = 1, separator: str = " ") -> str: def decimal(size: int, precision: Optional[int] = 1, separator: Optional[str] = " ") -> str:
"""Convert a filesize in to a string (powers of 1000, SI prefixes). """Convert a filesize in to a string (powers of 1000, SI prefixes).
In this convention, ``1000 B = 1 kB``. In this convention, ``1000 B = 1 kB``.