From 7df72f47296816ae7b47906ec76ba9c7e2f51856 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Fri, 20 Dec 2024 20:59:45 +0800 Subject: [PATCH 1/4] add type hint --- durationpy/duration.py | 4 ++-- durationpy/py.typed | 0 setup.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 durationpy/py.typed diff --git a/durationpy/duration.py b/durationpy/duration.py index 1e4b27d..a710d1f 100644 --- a/durationpy/duration.py +++ b/durationpy/duration.py @@ -36,7 +36,7 @@ class DurationError(ValueError): """duration error""" -def from_str(duration): +def from_str(duration: str) -> datetime.timedelta: """Parse a duration string to a datetime.timedelta""" original = duration @@ -72,7 +72,7 @@ def from_str(duration): microseconds = total / _microsecond_size return datetime.timedelta(microseconds=sign * microseconds) -def to_str(delta, extended=False): +def to_str(delta: datetime.timedelta, extended: bool = False) -> str: """Format a datetime.timedelta to a duration string""" total_seconds = delta.total_seconds() diff --git a/durationpy/py.typed b/durationpy/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py index 2f68c23..d43df64 100644 --- a/setup.py +++ b/setup.py @@ -9,5 +9,6 @@ download_url = 'https://github.com/icholy/durationpy/tarball/0.9', version = '0.9', packages = ['durationpy'], - license = 'MIT' + license = 'MIT', + package_data = {'durationpy': ['py.typed']}, ) From f9eeca3cd461fdb6c9319674f017fea8d248078e Mon Sep 17 00:00:00 2001 From: Trim21 Date: Sat, 17 May 2025 19:37:15 +0800 Subject: [PATCH 2/4] fix --- durationpy/__init__.pyi | 6 ++++++ durationpy/duration.py | 4 ++-- setup.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 durationpy/__init__.pyi diff --git a/durationpy/__init__.pyi b/durationpy/__init__.pyi new file mode 100644 index 0000000..61b460e --- /dev/null +++ b/durationpy/__init__.pyi @@ -0,0 +1,6 @@ +import datetime + +def from_str(duration: str) -> datetime.timedelta: ... +def to_str(delta: datetime.timedelta, extended: bool = ...) -> str: ... + +class DurationError(ValueError): ... diff --git a/durationpy/duration.py b/durationpy/duration.py index a710d1f..1e4b27d 100644 --- a/durationpy/duration.py +++ b/durationpy/duration.py @@ -36,7 +36,7 @@ class DurationError(ValueError): """duration error""" -def from_str(duration: str) -> datetime.timedelta: +def from_str(duration): """Parse a duration string to a datetime.timedelta""" original = duration @@ -72,7 +72,7 @@ def from_str(duration: str) -> datetime.timedelta: microseconds = total / _microsecond_size return datetime.timedelta(microseconds=sign * microseconds) -def to_str(delta: datetime.timedelta, extended: bool = False) -> str: +def to_str(delta, extended=False): """Format a datetime.timedelta to a duration string""" total_seconds = delta.total_seconds() diff --git a/setup.py b/setup.py index d43df64..ab8e2a0 100644 --- a/setup.py +++ b/setup.py @@ -10,5 +10,5 @@ version = '0.9', packages = ['durationpy'], license = 'MIT', - package_data = {'durationpy': ['py.typed']}, + package_data = {'durationpy': ['py.typed', '*.pyi']}, ) From a1c2d9eb31895710a1784ff31e1e502409f07fd2 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Sat, 17 May 2025 19:37:42 +0800 Subject: [PATCH 3/4] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ab8e2a0..409e11c 100644 --- a/setup.py +++ b/setup.py @@ -10,5 +10,5 @@ version = '0.9', packages = ['durationpy'], license = 'MIT', - package_data = {'durationpy': ['py.typed', '*.pyi']}, + package_data = {'durationpy': ['py.typed', '*.pyi']} ) From f03c9f3dac5bdcfc043003ca658b6917905d44df Mon Sep 17 00:00:00 2001 From: Trim21 Date: Sat, 17 May 2025 19:37:48 +0800 Subject: [PATCH 4/4] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 409e11c..18d2ae9 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,6 @@ download_url = 'https://github.com/icholy/durationpy/tarball/0.9', version = '0.9', packages = ['durationpy'], - license = 'MIT', - package_data = {'durationpy': ['py.typed', '*.pyi']} + package_data = {'durationpy': ['py.typed', '*.pyi']}, + license = 'MIT' )