Skip to content

Commit

Permalink
added all future annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekrubin committed Dec 19, 2024
1 parent f51562b commit 0077a5b
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 99 deletions.
6 changes: 4 additions & 2 deletions crates/ryo3/src/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ pub fn sleep(py: Python<'_>, secs: u64) -> PyResult<f64> {
}

#[pyfunction]
fn sleep_async(py: Python, secs: u64) -> PyResult<Bound<PyAny>> {
fn sleep_async(py: Python, secs: f64) -> PyResult<Bound<PyAny>> {
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)
})
}
Expand Down
76 changes: 76 additions & 0 deletions python/ry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -55,6 +78,7 @@
gzip_decode,
gzip_encode,
home,
home_dir,
jiter_cache_clear,
jiter_cache_usage,
kebab_case,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -149,6 +210,7 @@
"gzip_decode",
"gzip_encode",
"home",
"home_dir",
"jiter_cache_clear",
"jiter_cache_usage",
"kebab_case",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
9 changes: 0 additions & 9 deletions scripts/types_discrepancies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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__",
Expand Down
36 changes: 1 addition & 35 deletions tests/jiff/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions tests/jiff/test_tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 12 additions & 11 deletions tests/jiff/test_zoned_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/sqlformat/test_sqlfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])'

Expand Down
21 changes: 12 additions & 9 deletions tests/test_sleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import time

import pytest

import ry


Expand All @@ -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)
5 changes: 0 additions & 5 deletions tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions tests/unindent/test_unindent.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import ry


Expand Down
22 changes: 0 additions & 22 deletions tests/walkdir/test_walkdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
1 change: 0 additions & 1 deletion tests/xxhash/test_xxhash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest

# import ry
from ry import xxhash as ry_xxh

from ._xxhash_test_data import (
Expand Down

0 comments on commit 0077a5b

Please sign in to comment.