Skip to content

Commit

Permalink
typing
Browse files Browse the repository at this point in the history
  • Loading branch information
zigai committed Jan 17, 2025
1 parent e76e17c commit 86d0a16
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
6 changes: 3 additions & 3 deletions stdl/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import json
import sys
import time
import typing as T
from functools import wraps
from typing import Callable


def timer(
r: int | None = 2,
sink: T.Callable = sys.stdout.write,
sink: Callable = sys.stdout.write,
show_args: bool = False,
serialize: bool = False,
sep=" | ",
Expand All @@ -24,7 +24,7 @@ def timer(
sep (str, optional): Separator between the function/method name and the arguments. Defaults to " | ".
"""

def decorator(func: T.Callable):
def decorator(func: Callable):
@wraps(func)
def wrapper(*args, **kwargs):
time_start = time.perf_counter()
Expand Down
4 changes: 2 additions & 2 deletions stdl/dt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import random
import time
import typing as T
from dataclasses import dataclass
from datetime import date, datetime, timedelta, timezone
from typing import Generator

from dateutil.parser import parse as parse_datetime_str

Expand Down Expand Up @@ -220,7 +220,7 @@ def date_fmt(
return d.strftime(f"%{fmt[0]}{sep}%{fmt[1]}{sep}%{fmt[2]}")


def date_range(start: date, end: date) -> T.Generator[date, None, None]:
def date_range(start: date, end: date) -> Generator[date, None, None]:
"""
Returns a generator for dates between ``start`` and ``end``
Expand Down
16 changes: 8 additions & 8 deletions stdl/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import subprocess
import sys
import time
import typing as T
from collections.abc import Iterable
from datetime import datetime
from os import PathLike
from pathlib import Path
from queue import Queue
from typing import Any, Generator, Literal

import toml
import yaml
Expand Down Expand Up @@ -442,7 +442,7 @@ def pickle_load(filepath: str | PathLike):
return pickle.load(f)


def pickle_dump(data: T.Any, filepath: str | PathLike) -> None:
def pickle_dump(data: Any, filepath: str | PathLike) -> None:
"""Dumps an object to the specified filepath."""

with open(filepath, "wb") as f:
Expand Down Expand Up @@ -510,7 +510,7 @@ def json_append(


def json_dump(
data: T.Any, path: str | PathLike, encoding: str = "utf-8", default=str, indent=4
data: Any, path: str | PathLike, encoding: str = "utf-8", default=str, indent=4
) -> None:
"""
Dumps data to a JSON file.
Expand Down Expand Up @@ -646,7 +646,7 @@ def bytes_readable(size_bytes: int) -> str:
return f"{s} {size_name[i]}"


def readable_size_to_bytes(size: str, kb_size: T.Literal[1000, 1024] = 1024) -> int:
def readable_size_to_bytes(size: str, kb_size: Literal[1000, 1024] = 1024) -> int:
"""Convert human-readable string to bytes.
Args:
size (str): The number of bytes in human-readable format
Expand Down Expand Up @@ -729,7 +729,7 @@ def yield_files_in(
*,
recursive: bool = True,
abs: bool = True,
) -> T.Generator[str, None, None]:
) -> Generator[str, None, None]:
"""
Yields the paths of files in a directory.
Expand Down Expand Up @@ -812,7 +812,7 @@ def get_files_in(

def yield_dirs_in(
directory: str | Path, *, recursive: bool = True, abs: bool = True
) -> T.Generator[str, None, None]:
) -> Generator[str, None, None]:
"""
Yields paths to all directories in the specified directory.
Yielded paths are converted to absolute paths.
Expand Down Expand Up @@ -905,8 +905,8 @@ def __init__(
args,
returncode: int,
time_taken: float,
stdout: T.Any | None = None,
stderr: T.Any | None = None,
stdout: Any | None = None,
stderr: Any | None = None,
) -> None:
super().__init__(args, returncode, stdout, stderr)
self.time_taken = time_taken
Expand Down
8 changes: 4 additions & 4 deletions stdl/st.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import re
import textwrap
import typing as T
from dataclasses import dataclass
from platform import system
from sys import stdout
from typing import Literal

CSI_RESET = "\033["
NO_COLOR = bool(os.environ.get("NO_COLOR", False))
Expand Down Expand Up @@ -115,7 +115,7 @@ class ST(ColorANSI):
BLINK = ansi_code(5)


ForegroundColor = T.Literal[
ForegroundColor = Literal[
"black",
"blue",
"bold",
Expand All @@ -136,7 +136,7 @@ class ST(ColorANSI):
]


BackgroundColor = T.Literal[
BackgroundColor = Literal[
"black",
"blue",
"cyan",
Expand All @@ -155,7 +155,7 @@ class ST(ColorANSI):
"yellow",
]

Style = T.Literal["blink", "bold", "dim", "italic", "reset", "underline"]
Style = Literal["blink", "bold", "dim", "italic", "reset", "underline"]


def _get_ansi_value(value: str | None, handler) -> str:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_fs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json
import os
import tempfile
from pathlib import Path

Expand Down

0 comments on commit 86d0a16

Please sign in to comment.