From 7df72f47296816ae7b47906ec76ba9c7e2f51856 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Fri, 20 Dec 2024 20:59:45 +0800 Subject: [PATCH] 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']}, )