From 53f82fc88d56926c55d10d59fe78edd465da4dcb Mon Sep 17 00:00:00 2001 From: jesse Date: Thu, 6 Mar 2025 15:35:53 -0800 Subject: [PATCH] Types cleanup (#215) * types for unindent * moved types for libs aside from std to own stubs * moved std types to `_std.pyi` file * clean up more types * fix JSON type(s) --- python/ry/_types.py | 5 + python/ry/ryo3/JSON.pyi | 14 +- python/ry/ryo3/__init__.pyi | 486 ++++---------------------------- python/ry/ryo3/_brotli.pyi | 13 + python/ry/ryo3/_bzip2.pyi | 11 + python/ry/ryo3/_flate2.pyi | 14 + python/ry/ryo3/_fspath.pyi | 104 +++++++ python/ry/ryo3/_quick_maths.pyi | 24 ++ python/ry/ryo3/_same_file.pyi | 7 + python/ry/ryo3/_shlex.pyi | 7 + python/ry/ryo3/_std.pyi | 205 ++++++++++++++ python/ry/ryo3/_tokio.pyi | 4 +- python/ry/ryo3/_unindent.pyi | 6 + python/ry/ryo3/_walkdir.pyi | 54 ++++ python/ry/ryo3/_zstd.pyi | 12 + 15 files changed, 518 insertions(+), 448 deletions(-) create mode 100644 python/ry/ryo3/_brotli.pyi create mode 100644 python/ry/ryo3/_bzip2.pyi create mode 100644 python/ry/ryo3/_flate2.pyi create mode 100644 python/ry/ryo3/_fspath.pyi create mode 100644 python/ry/ryo3/_quick_maths.pyi create mode 100644 python/ry/ryo3/_same_file.pyi create mode 100644 python/ry/ryo3/_shlex.pyi create mode 100644 python/ry/ryo3/_std.pyi create mode 100644 python/ry/ryo3/_unindent.pyi create mode 100644 python/ry/ryo3/_walkdir.pyi create mode 100644 python/ry/ryo3/_zstd.pyi diff --git a/python/ry/_types.py b/python/ry/_types.py index 288c7a60..ec8841e0 100644 --- a/python/ry/_types.py +++ b/python/ry/_types.py @@ -3,20 +3,25 @@ from __future__ import annotations import sys +from os import PathLike from typing import TypedDict if sys.version_info >= (3, 12): from collections.abc import Buffer else: from typing_extensions import Buffer + __all__ = ( "Buffer", "DateTimeTypedDict", "DateTypedDict", + "FsPathLike", "TimeSpanTypedDict", "TimeTypedDict", ) +FsPathLike = str | PathLike[str] + # ============================================================================= # JIFF diff --git a/python/ry/ryo3/JSON.pyi b/python/ry/ryo3/JSON.pyi index 2fa13e99..9bdbafd6 100644 --- a/python/ry/ryo3/JSON.pyi +++ b/python/ry/ryo3/JSON.pyi @@ -29,15 +29,5 @@ def parse_json_bytes( catch_duplicate_keys: bool = False, float_mode: Literal["float", "decimal", "lossless-float"] | bool = False, ) -> JsonValue: ... -def parse_json_str( - data: str, - /, - *, - allow_inf_nan: bool = True, - cache_mode: Literal[True, False, "all", "keys", "none"] = "all", - partial_mode: Literal[True, False, "off", "on", "trailing-strings"] = False, - catch_duplicate_keys: bool = False, - float_mode: Literal["float", "decimal", "lossless-float"] | bool = False, -) -> JsonValue: ... -def jiter_cache_clear() -> None: ... -def jiter_cache_usage() -> int: ... +def json_cache_clear() -> None: ... +def json_cache_usage() -> int: ... diff --git a/python/ry/ryo3/__init__.pyi b/python/ry/ryo3/__init__.pyi index d571e9fe..263b09eb 100644 --- a/python/ry/ryo3/__init__.pyi +++ b/python/ry/ryo3/__init__.pyi @@ -4,19 +4,29 @@ from __future__ import annotations import datetime as pydt import typing as t -from os import PathLike -from pathlib import Path from ry import dirs as dirs # noqa: RUF100 from ry import http as http # noqa: RUF100 from ry import xxhash as xxhash # noqa: RUF100 from ry._types import Buffer as Buffer # noqa: RUF100 +from ry._types import FsPathLike from ry.http import Headers as Headers # noqa: RUF100 from ry.http import HttpStatus as HttpStatus # noqa: RUF100 +from ._brotli import brotli as brotli +from ._brotli import brotli_decode as brotli_decode +from ._brotli import brotli_encode as brotli_encode from ._bytes import Bytes as Bytes +from ._bzip2 import bzip2 as bzip2 +from ._bzip2 import bzip2_decode as bzip2_decode +from ._bzip2 import bzip2_encode as bzip2_encode +from ._flate2 import gunzip as gunzip +from ._flate2 import gzip as gzip +from ._flate2 import gzip_decode as gzip_decode +from ._flate2 import gzip_encode as gzip_encode from ._fnv import FnvHasher as FnvHasher from ._fnv import fnv1a as fnv1a +from ._fspath import FsPath as FsPath from ._globset import Glob as Glob from ._globset import GlobSet as GlobSet from ._globset import Globster as Globster @@ -61,18 +71,47 @@ from ._jiter import json_cache_clear as json_cache_clear from ._jiter import json_cache_usage as json_cache_usage from ._jiter import parse_json as parse_json from ._jiter import parse_json_bytes as parse_json_bytes +from ._quick_maths import quick_maths as quick_maths from ._regex import Regex as Regex from ._reqwest import HttpClient as HttpClient from ._reqwest import ReqwestError as ReqwestError from ._reqwest import Response as Response from ._reqwest import ResponseStream as ResponseStream from ._reqwest import fetch as fetch +from ._same_file import is_same_file as is_same_file +from ._shlex import shplit as shplit from ._size import SizeFormatter as SizeFormatter from ._size import fmt_size as fmt_size from ._size import parse_size as parse_size from ._sqlformat import SqlfmtQueryParams as SqlfmtQueryParams from ._sqlformat import sqlfmt as sqlfmt from ._sqlformat import sqlfmt_params as sqlfmt_params +from ._std import Duration as Duration +from ._std import FileType as FileType +from ._std import Instant as Instant +from ._std import Metadata as Metadata +from ._std import canonicalize as canonicalize +from ._std import copy as copy +from ._std import create_dir as create_dir +from ._std import create_dir_all as create_dir_all +from ._std import exists as exists +from ._std import instant as instant +from ._std import is_dir as is_dir +from ._std import is_file as is_file +from ._std import is_symlink as is_symlink +from ._std import metadata as metadata +from ._std import read as read +from ._std import read_bytes as read_bytes +from ._std import read_stream as read_stream +from ._std import read_text as read_text +from ._std import remove_dir as remove_dir +from ._std import remove_dir_all as remove_dir_all +from ._std import remove_file as remove_file +from ._std import rename as rename +from ._std import sleep as sleep +from ._std import write as write +from ._std import write_bytes as write_bytes +from ._std import write_text as write_text from ._tokio import asleep as asleep from ._tokio import copy_async as copy_async from ._tokio import create_dir_async as create_dir_async @@ -84,12 +123,23 @@ from ._tokio import remove_file_async as remove_file_async from ._tokio import rename_async as rename_async from ._tokio import sleep_async as sleep_async from ._tokio import write_async as write_async +from ._unindent import unindent as unindent +from ._unindent import unindent_bytes as unindent_bytes from ._url import URL as URL +from ._walkdir import WalkDirEntry as WalkDirEntry +from ._walkdir import WalkdirGen as WalkdirGen +from ._walkdir import walkdir as walkdir from ._which import which as which from ._which import which_all as which_all from ._which import which_re as which_re +from ._zstd import zstd as zstd +from ._zstd import zstd_decode as zstd_decode +from ._zstd import zstd_encode as zstd_encode from .errors import FeatureNotEnabledError as FeatureNotEnabledError +# ============================================================================= +# CONSTANTS +# ============================================================================= __version__: str __authors__: str __build_profile__: str @@ -98,303 +148,8 @@ __pkg_name__: str __description__: str # ============================================================================= -# TYPE ALIASES -# ============================================================================= - -# ============================================================================= -# STD::TIME -# ============================================================================= -class Duration: - ZERO: Duration - MIN: Duration - MAX: Duration - NANOSECOND: Duration - MICROSECOND: Duration - MILLISECOND: Duration - SECOND: Duration - - def __init__(self, secs: int = 0, nanos: int = 0) -> None: ... - def __eq__(self, other: object) -> bool: ... - def __ne__(self, other: object) -> bool: ... - def __lt__(self, other: Duration) -> bool: ... - def __le__(self, other: Duration) -> bool: ... - def __gt__(self, other: Duration) -> bool: ... - def __ge__(self, other: Duration) -> bool: ... - def __hash__(self) -> int: ... - def __richcmp__(self, other: Duration | pydt.timedelta, op: int) -> bool: ... - def __str__(self) -> str: ... - def abs_diff(self, other: Duration) -> Duration: ... - def sleep(self) -> None: ... - - # ========================================================================= - # PYTHON_CONVERSIONS - # ========================================================================= - @classmethod - def from_pytimedelta(cls: type[Duration], td: pydt.timedelta) -> Duration: ... - def to_pytimedelta(self) -> pydt.timedelta: ... - - # ========================================================================= - # PROPERTIES - # ========================================================================= - @property - def is_zero(self) -> bool: ... - @property - def nanos(self) -> int: ... - @property - def secs(self) -> int: ... - @property - def days(self) -> int: ... - @property - def seconds(self) -> int: ... - @property - def microseconds(self) -> int: ... - @property - def subsec_micros(self) -> int: ... - @property - def subsec_millis(self) -> int: ... - @property - def subsec_nanos(self) -> int: ... - - # ========================================================================= - # CLASSMETHODS - # ========================================================================= - @classmethod - def from_hours(cls, hours: int) -> Duration: ... - @classmethod - def from_micros(cls, micros: int) -> Duration: ... - @classmethod - def from_millis(cls, millis: int) -> Duration: ... - @classmethod - def from_mins(cls, mins: int) -> Duration: ... - @classmethod - def from_nanos(cls, nanos: int) -> Duration: ... - @classmethod - def from_secs(cls, secs: int) -> Duration: ... - @classmethod - def from_secs_f32(cls, secs: float) -> Duration: ... - @classmethod - def from_secs_f64(cls, secs: float) -> Duration: ... - @classmethod - def from_days(cls, days: int) -> Duration: ... - @classmethod - def from_weeks(cls, weeks: int) -> Duration: ... - def as_micros(self) -> int: ... - def as_millis(self) -> int: ... - def as_nanos(self) -> int: ... - def as_secs(self) -> int: ... - def as_secs_f32(self) -> float: ... - def as_secs_f64(self) -> float: ... - - # ========================================================================= - # NOT IMPLEMENTED - # ========================================================================= - def checked_add(self, other: Duration) -> Duration | None: ... - def checked_div(self, other: Duration) -> Duration | None: ... - def checked_mul(self, other: Duration) -> Duration | None: ... - def checked_sub(self, other: Duration) -> Duration | None: ... - def div_duration_f32(self, other: Duration) -> float: ... - def div_duration_f64(self, other: Duration) -> float: ... - def div_f32(self, other: float) -> Duration: ... - def div_f64(self, other: float) -> Duration: ... - def mul_f32(self, other: float) -> Duration: ... - def mul_f64(self, other: float) -> Duration: ... - def saturating_add(self, other: Duration) -> Duration: ... - def saturating_mul(self, other: Duration) -> Duration: ... - def saturating_sub(self, other: Duration) -> Duration: ... - -class Instant: - def __init__(self) -> None: ... - @classmethod - def now(cls) -> Instant: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __eq__(self, other: object) -> bool: ... - def __ne__(self, other: object) -> bool: ... - def __lt__(self, other: Instant) -> bool: ... - def __le__(self, other: Instant) -> bool: ... - def __gt__(self, other: Instant) -> bool: ... - def __ge__(self, other: Instant) -> bool: ... - def __hash__(self) -> int: ... - def __add__(self, other: Duration) -> Instant: ... - def __iadd__(self, other: Duration) -> Instant: ... - @t.overload - def __sub__(self, other: Duration) -> Instant: ... - @t.overload - def __sub__(self, other: Instant) -> Duration: ... - - # ========================================================================= - # INSTANCE METHODS - # ========================================================================= - def checked_add(self, other: Duration) -> Instant | None: ... - def checked_duration_since(self, earlier: Instant) -> Duration | None: ... - def checked_sub(self, other: Duration) -> Instant | None: ... - def duration_since(self, earlier: Instant) -> Duration: ... - def elapsed(self) -> Duration: ... - def saturating_duration_since(self, earlier: Instant) -> Duration: ... - -def instant() -> Instant: ... -def sleep(seconds: float) -> float: ... - -# ============================================================================= -# STD::FS +# SH # ============================================================================= -class FileType: - def __repr__(self) -> str: ... - @property - def is_dir(self) -> bool: ... - @property - def is_file(self) -> bool: ... - @property - def is_symlink(self) -> bool: ... - -class Metadata: - def __repr__(self) -> str: ... - @property - def file_type(self) -> FileType: ... - @property - def len(self) -> int: ... - @property - def is_empty(self) -> bool: ... - @property - def modified(self) -> pydt.datetime: ... - @property - def accessed(self) -> pydt.datetime: ... - @property - def created(self) -> pydt.datetime: ... - @property - def is_dir(self) -> bool: ... - @property - def is_file(self) -> bool: ... - @property - def is_symlink(self) -> bool: ... - -# ============================================================================= -# STD::FS ~ functions -# ============================================================================= -def read(path: FsPathLike) -> Bytes: ... -def read_bytes(path: FsPathLike) -> bytes: ... -def read_text(path: FsPathLike) -> str: ... -def read_stream( - path: FsPathLike, - chunk_size: int = 65536, - *, - offset: int = 0, # noqa: F811 -) -> t.Iterator[Bytes]: ... -def write(path: FsPathLike, data: Buffer | str) -> int: ... -def write_bytes(path: FsPathLike, data: bytes) -> int: ... -def write_text(path: FsPathLike, data: str) -> int: ... -def canonicalize(path: FsPathLike) -> FsPath: ... -def copy(from_path: FsPathLike, to_path: FsPathLike) -> int: ... -def create_dir(path: FsPathLike) -> None: ... -def create_dir_all(path: FsPathLike) -> None: ... -def exists(path: FsPathLike) -> bool: ... -def is_dir(path: FsPathLike) -> bool: ... -def is_file(path: FsPathLike) -> bool: ... -def is_symlink(path: FsPathLike) -> bool: ... -def metadata(path: FsPathLike) -> Metadata: ... -def remove_dir(path: FsPathLike) -> None: ... -def remove_dir_all(path: FsPathLike) -> None: ... -def remove_file(path: FsPathLike) -> None: ... -def rename(from_path: FsPathLike, to_path: FsPathLike) -> None: ... - -# ============================================================================= -# FSPATH -# ============================================================================= -class FsPath: - def __init__(self, path: PathLike[str] | str | None = None) -> None: ... - def __fspath__(self) -> str: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __hash__(self) -> int: ... - def __eq__(self, other: object) -> bool: ... - def __ne__(self, other: object) -> bool: ... - def __lt__(self, other: PathLike[str] | str) -> bool: ... - def __le__(self, other: PathLike[str] | str) -> bool: ... - def __gt__(self, other: PathLike[str] | str) -> bool: ... - def __ge__(self, other: PathLike[str] | str) -> bool: ... - def __truediv__(self, other: PathLike[str] | str) -> FsPath: ... - def __rtruediv__(self, other: PathLike[str] | str) -> FsPath: ... - def to_pathlib(self) -> Path: ... - def read(self) -> Bytes: ... - def read_text(self) -> str: ... - def read_bytes(self) -> bytes: ... - def absolute(self) -> FsPath: ... - def resolve(self) -> FsPath: ... - def write(self, data: Buffer | bytes) -> None: ... - def write_bytes(self, data: Buffer | bytes) -> None: ... - def write_text(self, data: str) -> None: ... - def joinpath(self, *paths: str) -> FsPath: ... - def exists(self) -> bool: ... - def with_name(self, name: str) -> FsPath: ... - def with_suffix(self, suffix: str) -> FsPath: ... - def iterdir(self) -> t.Iterator[FsPath]: ... - def relative_to(self, other: PathLike[str] | str | FsPath) -> FsPath: ... - def as_posix(self) -> str: ... - - # TODO - def __bytes__(self) -> bytes: ... - def as_uri(self) -> str: ... - def equiv(self, other: PathLike[str] | str | FsPath) -> bool: ... - def string(self) -> str: ... - def clone(self) -> FsPath: ... - - # ========================================================================= - # CLASSMETHODS - # ========================================================================= - @classmethod - def cwd(cls) -> FsPath: ... - @classmethod - def home(cls) -> FsPath: ... - - # ========================================================================= - # PROPERTIES - # ========================================================================= - @property - def anchor(self) -> str: ... - @property - def drive(self) -> str: ... - @property - def name(self) -> str: ... - @property - def parent(self) -> FsPath: ... - @property - def parents(self) -> t.Sequence[FsPath]: ... - @property - def parts(self) -> tuple[str, ...]: ... - @property - def root(self) -> str: ... - @property - def stem(self) -> str: ... - @property - def suffix(self) -> str: ... - @property - def suffixes(self) -> list[str]: ... - - # ========================================================================= - # std::path::PathBuf (deref -> std::path::Path) - # ========================================================================= - def ancestors(self) -> t.Iterator[FsPath]: ... - def canonicalize(self) -> FsPath: ... - def components(self) -> t.Iterator[FsPath]: ... - def display(self) -> str: ... - def ends_with(self, path: PathLike[str] | str) -> bool: ... - def extension(self) -> str: ... - def file_name(self) -> str: ... - def file_prefix(self) -> FsPath: ... - def file_stem(self) -> str: ... - def has_root(self) -> bool: ... - def is_absolute(self) -> bool: ... - def is_dir(self) -> bool: ... - def is_file(self) -> bool: ... - def is_relative(self) -> bool: ... - def is_symlink(self) -> bool: ... - def starts_with(self, path: PathLike[str] | str) -> bool: ... - def strip_prefix(self, prefix: PathLike[str] | str) -> FsPath: ... - def with_extension(self, ext: str) -> FsPath: ... - def with_file_name(self, name: str) -> FsPath: ... - -FsPathLike = str | PathLike[str] - def pwd() -> str: ... def home() -> str: ... def cd(path: FsPathLike) -> None: ... @@ -417,138 +172,3 @@ def ls( objects: t.Literal[True] = True, ) -> list[FsPath]: """List directory contents - returns list of FsPath objects""" - -def quick_maths() -> t.Literal[3]: - """Performs quick-maths - - Implements the algorithm for performing "quick-maths" as described by - Big Shaq in his PHD thesis, 2017, in which he states: - - > "2 plus 2 is 4, minus one that's 3, quick maths." (Big Shaq et al., 2017) - - Reference: - https://youtu.be/3M_5oYU-IsU?t=60 - - Example: - >>> import ry - >>> result = ry.quick_maths() - >>> assert result == 3 - - NOTE: THIS IS FROM MY TEMPLATE RY03-MODULE - """ - -# ----------------------------------------------------------------------------- -# \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ -# /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ -# ----------------------------------------------------------------------------- -# |~|~ LIBS ~|~ LIBS ~|~ LIBS ~|~ LIBS ~|~ LIBS ~|~ LIBS ~|~ LIBS ~|~ LIBS ~|~| -# ----------------------------------------------------------------------------- -# \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ -# /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ -# ----------------------------------------------------------------------------- - -# ============================================================================= -# WALKDIR -# ============================================================================= -class WalkDirEntry: - def __fspath__(self) -> str: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - @property - def path(self) -> FsPath: ... - @property - def file_name(self) -> str: ... - @property - def depth(self) -> int: ... - @property - def path_is_symlink(self) -> bool: ... - @property - def file_type(self) -> FileType: ... - @property - def is_dir(self) -> bool: ... - @property - def is_file(self) -> bool: ... - @property - def is_symlink(self) -> bool: ... - @property - def len(self) -> int: ... - -class WalkdirGen: - """walkdir::Walkdir iterable wrapper""" - - files: bool - dirs: bool - - def __next__(self) -> str: ... - def __iter__(self) -> t.Iterator[str]: ... - def collect(self) -> list[str]: ... - -def walkdir( - path: FsPathLike | None = None, - *, - files: bool = True, - dirs: bool = True, # noqa: F811 - contents_first: bool = False, - min_depth: int = 0, - max_depth: int | None = None, - follow_links: bool = False, - same_file_system: bool = False, - glob: Glob | GlobSet | Globster | t.Sequence[str] | str | None = None, # noqa: F811 -) -> WalkdirGen: ... - -# ============================================================================= -# SAME_FILE -# ============================================================================= - -def is_same_file(a: PathLike[str], b: PathLike[str]) -> bool: ... - -# ============================================================================= -# SHLEX -# ============================================================================= -def shplit(s: str) -> list[str]: - """shlex::split wrapper much like python's stdlib shlex.split but faster""" - ... - -# ============================================================================= -# FORMATTING -# ============================================================================= -def unindent(string: str) -> str: ... -def unindent_bytes(string: bytes) -> bytes: ... - -# ============================================================================= -# BROTLI -# ============================================================================= -def brotli_encode( - input: bytes, quality: int = 11, magic_number: bool = False -) -> bytes: ... -def brotli_decode(input: bytes) -> bytes: ... -def brotli(input: bytes, quality: int = 11, magic_number: bool = False) -> bytes: - """Alias for brotli_encode""" - -# ============================================================================= -# BZIP2 -# ============================================================================= -def bzip2_encode(input: bytes, quality: int = 9) -> bytes: ... -def bzip2_decode(input: bytes) -> bytes: ... -def bzip2(input: bytes, quality: int = 9) -> bytes: - """Alias for bzip2_encode""" - -# ============================================================================= -# GZIP -# ============================================================================= -def gzip_encode(input: bytes, quality: int = 9) -> bytes: ... -def gzip_decode(input: bytes) -> bytes: ... -def gzip(input: bytes, quality: int = 9) -> bytes: - """Alias for gzip_encode""" - -def gunzip(input: bytes) -> bytes: - """Alias for gzip_decode""" - -# ============================================================================= -# ZSTD -# ============================================================================= -def zstd_encode(input: bytes, level: int = 3) -> bytes: ... -def zstd(input: bytes, level: int = 3) -> bytes: - """Alias for zstd_encode""" - -def zstd_decode(input: bytes) -> bytes: ... diff --git a/python/ry/ryo3/_brotli.pyi b/python/ry/ryo3/_brotli.pyi new file mode 100644 index 00000000..2db5a399 --- /dev/null +++ b/python/ry/ryo3/_brotli.pyi @@ -0,0 +1,13 @@ +"""ryo3-brotli types""" + +from __future__ import annotations + +# ============================================================================= +# BROTLI +# ============================================================================= +def brotli_encode( + input: bytes, quality: int = 11, magic_number: bool = False +) -> bytes: ... +def brotli_decode(input: bytes) -> bytes: ... +def brotli(input: bytes, quality: int = 11, magic_number: bool = False) -> bytes: + """Alias for brotli_encode""" diff --git a/python/ry/ryo3/_bzip2.pyi b/python/ry/ryo3/_bzip2.pyi new file mode 100644 index 00000000..a55e142f --- /dev/null +++ b/python/ry/ryo3/_bzip2.pyi @@ -0,0 +1,11 @@ +"""ryo3-bzip2 types""" + +from __future__ import annotations + +# ============================================================================= +# BZIP2 +# ============================================================================= +def bzip2_encode(input: bytes, quality: int = 9) -> bytes: ... +def bzip2_decode(input: bytes) -> bytes: ... +def bzip2(input: bytes, quality: int = 9) -> bytes: + """Alias for bzip2_encode""" diff --git a/python/ry/ryo3/_flate2.pyi b/python/ry/ryo3/_flate2.pyi new file mode 100644 index 00000000..54b89df1 --- /dev/null +++ b/python/ry/ryo3/_flate2.pyi @@ -0,0 +1,14 @@ +"""ryo3-flate2 types""" + +from __future__ import annotations + +# ============================================================================= +# GZIP +# ============================================================================= +def gzip_encode(input: bytes, quality: int = 9) -> bytes: ... +def gzip_decode(input: bytes) -> bytes: ... +def gzip(input: bytes, quality: int = 9) -> bytes: + """Alias for gzip_encode""" + +def gunzip(input: bytes) -> bytes: + """Alias for gzip_decode""" diff --git a/python/ry/ryo3/_fspath.pyi b/python/ry/ryo3/_fspath.pyi new file mode 100644 index 00000000..c30fea63 --- /dev/null +++ b/python/ry/ryo3/_fspath.pyi @@ -0,0 +1,104 @@ +"""ryo3-fspath types""" + +from __future__ import annotations + +import typing as t +from os import PathLike +from pathlib import Path + +from ry import Bytes +from ry._types import Buffer + +# ============================================================================= +# FSPATH +# ============================================================================= +class FsPath: + def __init__(self, path: PathLike[str] | str | None = None) -> None: ... + def __fspath__(self) -> str: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __hash__(self) -> int: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __lt__(self, other: PathLike[str] | str) -> bool: ... + def __le__(self, other: PathLike[str] | str) -> bool: ... + def __gt__(self, other: PathLike[str] | str) -> bool: ... + def __ge__(self, other: PathLike[str] | str) -> bool: ... + def __truediv__(self, other: PathLike[str] | str) -> FsPath: ... + def __rtruediv__(self, other: PathLike[str] | str) -> FsPath: ... + def __bytes__(self) -> bytes: ... + def to_pathlib(self) -> Path: ... + def read(self) -> Bytes: ... + def read_text(self) -> str: ... + def read_bytes(self) -> bytes: ... + def absolute(self) -> FsPath: ... + def resolve(self) -> FsPath: ... + def write(self, data: Buffer | bytes) -> None: ... + def write_bytes(self, data: Buffer | bytes) -> None: ... + def write_text(self, data: str) -> None: ... + def joinpath(self, *paths: str) -> FsPath: ... + def exists(self) -> bool: ... + def with_name(self, name: str) -> FsPath: ... + def with_suffix(self, suffix: str) -> FsPath: ... + def iterdir(self) -> t.Iterator[FsPath]: ... + def relative_to(self, other: PathLike[str] | str | FsPath) -> FsPath: ... + def as_posix(self) -> str: ... + def as_uri(self) -> str: ... + def equiv(self, other: PathLike[str] | str | FsPath) -> bool: ... + def string(self) -> str: ... + def clone(self) -> FsPath: ... + + # ========================================================================= + # CLASSMETHODS + # ========================================================================= + @classmethod + def cwd(cls) -> FsPath: ... + @classmethod + def home(cls) -> FsPath: ... + + # ========================================================================= + # PROPERTIES + # ========================================================================= + @property + def anchor(self) -> str: ... + @property + def drive(self) -> str: ... + @property + def name(self) -> str: ... + @property + def parent(self) -> FsPath: ... + @property + def parents(self) -> t.Sequence[FsPath]: ... + @property + def parts(self) -> tuple[str, ...]: ... + @property + def root(self) -> str: ... + @property + def stem(self) -> str: ... + @property + def suffix(self) -> str: ... + @property + def suffixes(self) -> list[str]: ... + + # ========================================================================= + # std::path::PathBuf (deref -> std::path::Path) + # ========================================================================= + def ancestors(self) -> t.Iterator[FsPath]: ... + def canonicalize(self) -> FsPath: ... + def components(self) -> t.Iterator[FsPath]: ... + def display(self) -> str: ... + def ends_with(self, path: PathLike[str] | str) -> bool: ... + def extension(self) -> str: ... + def file_name(self) -> str: ... + def file_prefix(self) -> FsPath: ... + def file_stem(self) -> str: ... + def has_root(self) -> bool: ... + def is_absolute(self) -> bool: ... + def is_dir(self) -> bool: ... + def is_file(self) -> bool: ... + def is_relative(self) -> bool: ... + def is_symlink(self) -> bool: ... + def starts_with(self, path: PathLike[str] | str) -> bool: ... + def strip_prefix(self, prefix: PathLike[str] | str) -> FsPath: ... + def with_extension(self, ext: str) -> FsPath: ... + def with_file_name(self, name: str) -> FsPath: ... diff --git a/python/ry/ryo3/_quick_maths.pyi b/python/ry/ryo3/_quick_maths.pyi new file mode 100644 index 00000000..be6d99f1 --- /dev/null +++ b/python/ry/ryo3/_quick_maths.pyi @@ -0,0 +1,24 @@ +"""ryo3-quick-maths types""" + +from __future__ import annotations + +import typing as t + +def quick_maths() -> t.Literal[3]: + """Performs quick-maths + + Implements the algorithm for performing "quick-maths" as described by + Big Shaq in his PHD thesis, 2017, in which he states: + + > "2 plus 2 is 4, minus one that's 3, quick maths." (Big Shaq et al., 2017) + + Reference: + https://youtu.be/3M_5oYU-IsU?t=60 + + Example: + >>> import ry + >>> result = ry.quick_maths() + >>> assert result == 3 + + NOTE: THIS IS FROM MY TEMPLATE RY03-MODULE + """ diff --git a/python/ry/ryo3/_same_file.pyi b/python/ry/ryo3/_same_file.pyi new file mode 100644 index 00000000..9a16f650 --- /dev/null +++ b/python/ry/ryo3/_same_file.pyi @@ -0,0 +1,7 @@ +"""ryo3-same-file types""" + +from __future__ import annotations + +from os import PathLike + +def is_same_file(a: PathLike[str], b: PathLike[str]) -> bool: ... diff --git a/python/ry/ryo3/_shlex.pyi b/python/ry/ryo3/_shlex.pyi new file mode 100644 index 00000000..04c6d60c --- /dev/null +++ b/python/ry/ryo3/_shlex.pyi @@ -0,0 +1,7 @@ +"""ryo3-shlex types""" + +from __future__ import annotations + +def shplit(s: str) -> list[str]: + """shlex::split wrapper much like python's stdlib shlex.split but faster""" + ... diff --git a/python/ry/ryo3/_std.pyi b/python/ry/ryo3/_std.pyi new file mode 100644 index 00000000..f92ea81d --- /dev/null +++ b/python/ry/ryo3/_std.pyi @@ -0,0 +1,205 @@ +"""ryo3-std types""" + +from __future__ import annotations + +import datetime as pydt +import typing as t + +from ry import Bytes, FsPath +from ry._types import Buffer, FsPathLike + +# ============================================================================= +# STD::TIME +# ============================================================================= +class Duration: + ZERO: Duration + MIN: Duration + MAX: Duration + NANOSECOND: Duration + MICROSECOND: Duration + MILLISECOND: Duration + SECOND: Duration + + def __init__(self, secs: int = 0, nanos: int = 0) -> None: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __lt__(self, other: Duration) -> bool: ... + def __le__(self, other: Duration) -> bool: ... + def __gt__(self, other: Duration) -> bool: ... + def __ge__(self, other: Duration) -> bool: ... + def __hash__(self) -> int: ... + def __richcmp__(self, other: Duration | pydt.timedelta, op: int) -> bool: ... + def __str__(self) -> str: ... + def abs_diff(self, other: Duration) -> Duration: ... + def sleep(self) -> None: ... + + # ========================================================================= + # PYTHON_CONVERSIONS + # ========================================================================= + @classmethod + def from_pytimedelta(cls: type[Duration], td: pydt.timedelta) -> Duration: ... + def to_pytimedelta(self) -> pydt.timedelta: ... + + # ========================================================================= + # PROPERTIES + # ========================================================================= + @property + def is_zero(self) -> bool: ... + @property + def nanos(self) -> int: ... + @property + def secs(self) -> int: ... + @property + def days(self) -> int: ... + @property + def seconds(self) -> int: ... + @property + def microseconds(self) -> int: ... + @property + def subsec_micros(self) -> int: ... + @property + def subsec_millis(self) -> int: ... + @property + def subsec_nanos(self) -> int: ... + + # ========================================================================= + # CLASSMETHODS + # ========================================================================= + @classmethod + def from_hours(cls, hours: int) -> Duration: ... + @classmethod + def from_micros(cls, micros: int) -> Duration: ... + @classmethod + def from_millis(cls, millis: int) -> Duration: ... + @classmethod + def from_mins(cls, mins: int) -> Duration: ... + @classmethod + def from_nanos(cls, nanos: int) -> Duration: ... + @classmethod + def from_secs(cls, secs: int) -> Duration: ... + @classmethod + def from_secs_f32(cls, secs: float) -> Duration: ... + @classmethod + def from_secs_f64(cls, secs: float) -> Duration: ... + @classmethod + def from_days(cls, days: int) -> Duration: ... + @classmethod + def from_weeks(cls, weeks: int) -> Duration: ... + def as_micros(self) -> int: ... + def as_millis(self) -> int: ... + def as_nanos(self) -> int: ... + def as_secs(self) -> int: ... + def as_secs_f32(self) -> float: ... + def as_secs_f64(self) -> float: ... + + # ========================================================================= + # NOT IMPLEMENTED + # ========================================================================= + def checked_add(self, other: Duration) -> Duration | None: ... + def checked_div(self, other: Duration) -> Duration | None: ... + def checked_mul(self, other: Duration) -> Duration | None: ... + def checked_sub(self, other: Duration) -> Duration | None: ... + def div_duration_f32(self, other: Duration) -> float: ... + def div_duration_f64(self, other: Duration) -> float: ... + def div_f32(self, other: float) -> Duration: ... + def div_f64(self, other: float) -> Duration: ... + def mul_f32(self, other: float) -> Duration: ... + def mul_f64(self, other: float) -> Duration: ... + def saturating_add(self, other: Duration) -> Duration: ... + def saturating_mul(self, other: Duration) -> Duration: ... + def saturating_sub(self, other: Duration) -> Duration: ... + +class Instant: + def __init__(self) -> None: ... + @classmethod + def now(cls) -> Instant: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __lt__(self, other: Instant) -> bool: ... + def __le__(self, other: Instant) -> bool: ... + def __gt__(self, other: Instant) -> bool: ... + def __ge__(self, other: Instant) -> bool: ... + def __hash__(self) -> int: ... + def __add__(self, other: Duration) -> Instant: ... + def __iadd__(self, other: Duration) -> Instant: ... + @t.overload + def __sub__(self, other: Duration) -> Instant: ... + @t.overload + def __sub__(self, other: Instant) -> Duration: ... + + # ========================================================================= + # INSTANCE METHODS + # ========================================================================= + def checked_add(self, other: Duration) -> Instant | None: ... + def checked_duration_since(self, earlier: Instant) -> Duration | None: ... + def checked_sub(self, other: Duration) -> Instant | None: ... + def duration_since(self, earlier: Instant) -> Duration: ... + def elapsed(self) -> Duration: ... + def saturating_duration_since(self, earlier: Instant) -> Duration: ... + +def instant() -> Instant: ... +def sleep(seconds: float) -> float: ... + +# ============================================================================= +# STD::FS +# ============================================================================= +class FileType: + def __repr__(self) -> str: ... + @property + def is_dir(self) -> bool: ... + @property + def is_file(self) -> bool: ... + @property + def is_symlink(self) -> bool: ... + +class Metadata: + def __repr__(self) -> str: ... + @property + def file_type(self) -> FileType: ... + @property + def len(self) -> int: ... + @property + def is_empty(self) -> bool: ... + @property + def modified(self) -> pydt.datetime: ... + @property + def accessed(self) -> pydt.datetime: ... + @property + def created(self) -> pydt.datetime: ... + @property + def is_dir(self) -> bool: ... + @property + def is_file(self) -> bool: ... + @property + def is_symlink(self) -> bool: ... + +# ============================================================================= +# STD::FS ~ functions +# ============================================================================= +def read(path: FsPathLike) -> Bytes: ... +def read_bytes(path: FsPathLike) -> bytes: ... +def read_text(path: FsPathLike) -> str: ... +def read_stream( + path: FsPathLike, + chunk_size: int = 65536, + *, + offset: int = 0, # noqa: F811 +) -> t.Iterator[Bytes]: ... +def write(path: FsPathLike, data: Buffer | str) -> int: ... +def write_bytes(path: FsPathLike, data: bytes) -> int: ... +def write_text(path: FsPathLike, data: str) -> int: ... +def canonicalize(path: FsPathLike) -> FsPath: ... +def copy(from_path: FsPathLike, to_path: FsPathLike) -> int: ... +def create_dir(path: FsPathLike) -> None: ... +def create_dir_all(path: FsPathLike) -> None: ... +def exists(path: FsPathLike) -> bool: ... +def is_dir(path: FsPathLike) -> bool: ... +def is_file(path: FsPathLike) -> bool: ... +def is_symlink(path: FsPathLike) -> bool: ... +def metadata(path: FsPathLike) -> Metadata: ... +def remove_dir(path: FsPathLike) -> None: ... +def remove_dir_all(path: FsPathLike) -> None: ... +def remove_file(path: FsPathLike) -> None: ... +def rename(from_path: FsPathLike, to_path: FsPathLike) -> None: ... diff --git a/python/ry/ryo3/_tokio.pyi b/python/ry/ryo3/_tokio.pyi index cc619c7f..62637ccf 100644 --- a/python/ry/ryo3/_tokio.pyi +++ b/python/ry/ryo3/_tokio.pyi @@ -5,13 +5,11 @@ from __future__ import annotations from typing import NoReturn from ry import Bytes -from ry._types import Buffer -from ry.ryo3 import FsPathLike +from ry._types import Buffer, FsPathLike # ============================================================================= # FS # ============================================================================= - async def copy_async(src: FsPathLike, dst: FsPathLike) -> None: ... async def create_dir_async(path: FsPathLike) -> None: ... async def metadata_async(path: FsPathLike) -> None: ... diff --git a/python/ry/ryo3/_unindent.pyi b/python/ry/ryo3/_unindent.pyi new file mode 100644 index 00000000..94ec596a --- /dev/null +++ b/python/ry/ryo3/_unindent.pyi @@ -0,0 +1,6 @@ +"""ryo3-unindent types""" + +from __future__ import annotations + +def unindent(string: str) -> str: ... +def unindent_bytes(string: bytes) -> bytes: ... diff --git a/python/ry/ryo3/_walkdir.pyi b/python/ry/ryo3/_walkdir.pyi new file mode 100644 index 00000000..2cc98a56 --- /dev/null +++ b/python/ry/ryo3/_walkdir.pyi @@ -0,0 +1,54 @@ +"""ryo3-walkdir types""" + +from __future__ import annotations + +import typing as t +from os import PathLike + +from ry import FileType, FsPath, Glob, GlobSet, Globster + +class WalkDirEntry: + def __fspath__(self) -> str: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + @property + def path(self) -> FsPath: ... + @property + def file_name(self) -> str: ... + @property + def depth(self) -> int: ... + @property + def path_is_symlink(self) -> bool: ... + @property + def file_type(self) -> FileType: ... + @property + def is_dir(self) -> bool: ... + @property + def is_file(self) -> bool: ... + @property + def is_symlink(self) -> bool: ... + @property + def len(self) -> int: ... + +class WalkdirGen: + """walkdir::Walkdir iterable wrapper""" + + files: bool + dirs: bool + + def __next__(self) -> str: ... + def __iter__(self) -> t.Iterator[str]: ... + def collect(self) -> list[str]: ... + +def walkdir( + path: str | PathLike[str] | None = None, + *, + files: bool = True, + dirs: bool = True, + contents_first: bool = False, + min_depth: int = 0, + max_depth: int | None = None, + follow_links: bool = False, + same_file_system: bool = False, + glob: Glob | GlobSet | Globster | t.Sequence[str] | str | None = None, +) -> WalkdirGen: ... diff --git a/python/ry/ryo3/_zstd.pyi b/python/ry/ryo3/_zstd.pyi new file mode 100644 index 00000000..66e42c81 --- /dev/null +++ b/python/ry/ryo3/_zstd.pyi @@ -0,0 +1,12 @@ +"""ryo3-zstd types""" + +from __future__ import annotations + +# ============================================================================= +# ZSTD +# ============================================================================= + +def zstd_decode(input: bytes) -> bytes: ... +def zstd_encode(input: bytes, level: int = 3) -> bytes: ... +def zstd(input: bytes, level: int = 3) -> bytes: + """Alias for zstd_encode"""