From 0077a5b0285781604902fdd4c2607e560558961e Mon Sep 17 00:00:00 2001 From: jessekrubin Date: Wed, 18 Dec 2024 18:37:13 -0800 Subject: [PATCH] added all future annotations --- crates/ryo3/src/sleep.rs | 6 ++- python/ry/__init__.py | 76 +++++++++++++++++++++++++++++++++ scripts/types_discrepancies.py | 9 ---- tests/jiff/test_time.py | 36 +--------------- tests/jiff/test_tz.py | 4 -- tests/jiff/test_zoned_diff.py | 23 +++++----- tests/sqlformat/test_sqlfmt.py | 1 - tests/test_sleep.py | 21 +++++---- tests/test_version.py | 5 --- tests/unindent/test_unindent.py | 2 + tests/walkdir/test_walkdir.py | 22 ---------- tests/xxhash/test_xxhash.py | 1 - 12 files changed, 107 insertions(+), 99 deletions(-) diff --git a/crates/ryo3/src/sleep.rs b/crates/ryo3/src/sleep.rs index 553d28d..17e9bb4 100644 --- a/crates/ryo3/src/sleep.rs +++ b/crates/ryo3/src/sleep.rs @@ -11,9 +11,11 @@ pub fn sleep(py: Python<'_>, secs: u64) -> PyResult { } #[pyfunction] -fn sleep_async(py: Python, secs: u64) -> PyResult> { +fn sleep_async(py: Python, secs: f64) -> PyResult> { pyo3_async_runtimes::tokio::future_into_py(py, async move { - tokio::time::sleep(Duration::from_secs(secs)).await; + let dur = Duration::from_secs_f64(secs); + + tokio::time::sleep(dur).await; Ok(secs) }) } diff --git a/python/ry/__init__.py b/python/ry/__init__.py index bd90592..2a6d3a9 100644 --- a/python/ry/__init__.py +++ b/python/ry/__init__.py @@ -35,18 +35,41 @@ __pkg_name__, __version__, _dev, + audio, + audio_dir, brotli, brotli_decode, brotli_encode, bzip2, bzip2_decode, bzip2_encode, + cache, + cache_dir, camel_case, cd, + config, + config_dir, + config_local, + config_local_dir, + data, + data_dir, + data_local, + data_local_dir, date, datetime, + desktop, + desktop_dir, + dirs, + document, + document_dir, + download, + download_dir, + executable, + executable_dir, fmt_nbytes, fnv1a, + font, + font_dir, fspaths, glob, globs, @@ -55,6 +78,7 @@ gzip_decode, gzip_encode, home, + home_dir, jiter_cache_clear, jiter_cache_usage, kebab_case, @@ -64,10 +88,18 @@ parse_json_bytes, parse_json_str, pascal_case, + picture, + picture_dir, + preference, + preference_dir, + public, + public_dir, pwd, quick_maths, read_bytes, read_text, + runtime, + runtime_dir, shouty_kebab_case, shouty_snake_case, shplit, @@ -77,12 +109,18 @@ snek_case, sqlfmt, sqlfmt_params, + state, + state_dir, + template, + template_dir, time, timespan, title_case, train_case, unindent, unindent_bytes, + video, + video_dir, walkdir, which, which_all, @@ -129,18 +167,41 @@ "__pkg_name__", "__version__", "_dev", + "audio", + "audio_dir", "brotli", "brotli_decode", "brotli_encode", "bzip2", "bzip2_decode", "bzip2_encode", + "cache", + "cache_dir", "camel_case", "cd", + "config", + "config_dir", + "config_local", + "config_local_dir", + "data", + "data_dir", + "data_local", + "data_local_dir", "date", "datetime", + "desktop", + "desktop_dir", + "dirs", + "document", + "document_dir", + "download", + "download_dir", + "executable", + "executable_dir", "fmt_nbytes", "fnv1a", + "font", + "font_dir", "fspaths", "glob", "globs", @@ -149,6 +210,7 @@ "gzip_decode", "gzip_encode", "home", + "home_dir", "jiter_cache_clear", "jiter_cache_usage", "kebab_case", @@ -158,10 +220,18 @@ "parse_json_bytes", "parse_json_str", "pascal_case", + "picture", + "picture_dir", + "preference", + "preference_dir", + "public", + "public_dir", "pwd", "quick_maths", "read_bytes", "read_text", + "runtime", + "runtime_dir", "ryo3", "shouty_kebab_case", "shouty_snake_case", @@ -172,12 +242,18 @@ "snek_case", "sqlfmt", "sqlfmt_params", + "state", + "state_dir", + "template", + "template_dir", "time", "timespan", "title_case", "train_case", "unindent", "unindent_bytes", + "video", + "video_dir", "walkdir", "which", "which_all", diff --git a/scripts/types_discrepancies.py b/scripts/types_discrepancies.py index a3a4505..0293109 100644 --- a/scripts/types_discrepancies.py +++ b/scripts/types_discrepancies.py @@ -20,7 +20,6 @@ def load_types() -> griffe.Object | griffe.Alias: TYPES_PATH, __dirname / "ryo3types", dirs_exist_ok=True, copy_function=copy2 ) # get the dummy types thingy - # print(TYPES_PATH) types_package = griffe.load("ryo3types") return types_package @@ -30,14 +29,6 @@ def load_ry() -> griffe.Object | griffe.Alias: return ry_package -# my_package = load_types() -# types_dict = my_package.as_dict() -# print(types_dict) -# get the actual ry duration -# ry_package_duration = griffe.load("ry.Duration", resolve_aliases=True) - -# ry_package_duration_dict = ry_package_duration.as_dict() - IGNORED_MEMBERS = { "__add__", "__class__", diff --git a/tests/jiff/test_time.py b/tests/jiff/test_time.py index 47e025a..0c8d9b4 100644 --- a/tests/jiff/test_time.py +++ b/tests/jiff/test_time.py @@ -124,40 +124,6 @@ def test_time_series_jiff_hash_unique(self) -> None: assert set(every_third_hour) == every_third_hour_set -# use jiff::{civil::time, Unit}; -# -# let t = time(15, 45, 10, 123_456_789); -# assert_eq!( -# t.round(Unit::Second)?, -# time(15, 45, 10, 0), -# ); -# let t = time(15, 45, 10, 500_000_001); -# assert_eq!( -# t.round(Unit::Second)?, -# time(15, 45, 11, 0), -# ); -# -# -# Example: changing the rounding mode -# The default rounding mode is RoundMode::HalfExpand, which breaks ties by rounding away from zero. But other modes like RoundMode::Trunc can be used too: -# use jiff::{civil::{TimeRound, time}, RoundMode, Unit}; -# -# let t = time(15, 45, 10, 999_999_999); -# assert_eq!( -# t.round(Unit::Second)?, -# time(15, 45, 11, 0), -# ); -# // The default will round up to the next second for any fraction -# // greater than or equal to 0.5. But truncation will always round -# // toward zero. -# assert_eq!( -# t.round( -# TimeRound::new().smallest(Unit::Second).mode(RoundMode::Trunc), -# )?, -# time(15, 45, 10, 0), -# ); - - class TestTimeRound: def test_time_round_docs_example(self) -> None: t = ry.time(15, 45, 10, 123_456_789) @@ -166,7 +132,7 @@ def test_time_round_docs_example(self) -> None: t = ry.time(15, 45, 10, 500_000_001) assert t.round(smallest="second") == ry.time(15, 45, 11, 0) - def test_round_Example_changing_the_rounding_mode(self) -> None: + def test_round_example_changing_the_rounding_mode(self) -> None: t = ry.time(15, 45, 10, 999_999_999) assert t.round(smallest="second") == ry.time(15, 45, 11, 0) assert t.round(smallest="second", mode="trunc") == ry.time(15, 45, 10, 0) diff --git a/tests/jiff/test_tz.py b/tests/jiff/test_tz.py index ec69a30..50c63f8 100644 --- a/tests/jiff/test_tz.py +++ b/tests/jiff/test_tz.py @@ -31,11 +31,7 @@ def test_timezone_from_str() -> None: ] for tz in timezones2test: - # py_tz = pydt.timezone(tz) - # assert py_tz.tzname(None) == ry_tz.name - ry_tz = ry.TimeZone(tz) - assert isinstance(ry_tz, ry.TimeZone) pytzinfo = ry_tz.to_pytzinfo() assert isinstance(pytzinfo, pydt.tzinfo) diff --git a/tests/jiff/test_zoned_diff.py b/tests/jiff/test_zoned_diff.py index c93f0fc..60bb76b 100644 --- a/tests/jiff/test_zoned_diff.py +++ b/tests/jiff/test_zoned_diff.py @@ -2,20 +2,21 @@ import ry.dev as ry -""" -use jiff::{civil::date, ToSpan}; - -let earlier = date(2006, 8, 24).at(22, 30, 0, 0).intz("America/New_York")?; -let later = date(2019, 1, 31).at(21, 0, 0, 0).intz("America/New_York")?; -assert_eq!(earlier.until(&later)?, 109_031.hours().minutes(30)); - -// Flipping the dates is fine, but you'll get a negative span. -assert_eq!(later.until(&earlier)?, -109_031.hours().minutes(30)); -""" - class TestZonedUntil: def test_zoned_until(self) -> None: + """ + ```rust + use jiff::{civil::date, ToSpan}; + + let earlier = date(2006, 8, 24).at(22, 30, 0, 0).intz("America/New_York")?; + let later = date(2019, 1, 31).at(21, 0, 0, 0).intz("America/New_York")?; + assert_eq!(earlier.until(&later)?, 109_031.hours().minutes(30)); + + // Flipping the dates is fine, but you'll get a negative span. + assert_eq!(later.until(&earlier)?, -109_031.hours().minutes(30)); + ``` + """ earlier = ry.date(2006, 8, 24).at(22, 30, 0, 0).intz("America/New_York") later = ry.date(2019, 1, 31).at(21, 0, 0, 0).intz("America/New_York") assert earlier.until(later) == ry.timespan(hours=109_031, minutes=30) diff --git a/tests/sqlformat/test_sqlfmt.py b/tests/sqlformat/test_sqlfmt.py index eb286e4..3a44aea 100644 --- a/tests/sqlformat/test_sqlfmt.py +++ b/tests/sqlformat/test_sqlfmt.py @@ -4,7 +4,6 @@ def test_sqlfmt_params() -> None: - # myparams = [1, "2", 3.0] params = ry.sqlfmt_params([1, 2]) assert str(params) == 'SqlfmtQueryParams(["1", "2"])' diff --git a/tests/test_sleep.py b/tests/test_sleep.py index 37ec4c5..6b1c9f8 100644 --- a/tests/test_sleep.py +++ b/tests/test_sleep.py @@ -2,6 +2,8 @@ import time +import pytest + import ry @@ -14,12 +16,13 @@ def test_sleep() -> None: assert end - start >= 0 -# @pytest.mark.asyncio -# async def test_sleep_async() -> None: -# start = time.time() -# res = await ry.sleep_async(0) -# end = time.time() -# # is float -# assert isinstance(res, float) -# assert res >= 0 -# assert end - start >= 0 +@pytest.mark.asyncio +async def test_sleep_async() -> None: + start = time.time() + res = await ry.sleep_async(0) + end = time.time() + # is float + assert res >= 0 + assert end - start >= 0 + + # assert isinstance(res, float) diff --git a/tests/test_version.py b/tests/test_version.py index 6c6d57a..cf39126 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -47,8 +47,3 @@ def test_version() -> None: cargo_version = _version_from_workspace_package() assert ry.__version__ == cargo_version - - # pyproject_dict = tomli.loads(Path(PYPROJECT_TOML).read_text()) - # print(pyproject_dict) - # pyproject_version = pyproject_dict["project"]["version"] - # assert ry.__version__ == pyproject_version diff --git a/tests/unindent/test_unindent.py b/tests/unindent/test_unindent.py index 41897ab..1afd76d 100644 --- a/tests/unindent/test_unindent.py +++ b/tests/unindent/test_unindent.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import ry diff --git a/tests/walkdir/test_walkdir.py b/tests/walkdir/test_walkdir.py index 51d4f98..dc868b6 100644 --- a/tests/walkdir/test_walkdir.py +++ b/tests/walkdir/test_walkdir.py @@ -73,28 +73,6 @@ def test_walk_dir_dirpath_none_use_pwd(tmp_path: Path) -> None: assert walkdir_paths_set == expected -# def test_walkdir_objects_and_strings(tmp_path: Path) -> None: -# dirtree = mk_dir_tree(tmp_path) -# walkdir_strings = [ -# e if e != "" else "." -# for e in ( -# str(f).replace(str(tmp_path), "").lstrip("/").lstrip("\\") -# for f in ry.walkdir(tmp_path, files=True, dirs=False) -# ) -# ] -# assert all(isinstance(e, str) for e in walkdir_strings) -# walkdir_paths = [ -# f for f in ry.walkdir(tmp_path, files=True, dirs=False) -# ] -# -# for thing in walkdir_paths: -# print(thing, type(thing)) -# print(walkdir_paths) -# assert all(isinstance(e, ry.FsPath) for e in walkdir_paths) -# -# assert set(walkdir_strings) == set(map(str, dirtree.filepaths)) - - def test_walk_dir_dirpath_string_files_only(tmp_path: Path) -> None: dirtree = mk_dir_tree(tmp_path) walkdir_paths = [ diff --git a/tests/xxhash/test_xxhash.py b/tests/xxhash/test_xxhash.py index 5eb140e..85c314d 100644 --- a/tests/xxhash/test_xxhash.py +++ b/tests/xxhash/test_xxhash.py @@ -2,7 +2,6 @@ import pytest -# import ry from ry import xxhash as ry_xxh from ._xxhash_test_data import (