Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: adding type hints #70

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions edtf/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ def dt_to_struct_time(dt):
return struct_time(
[dt.year, dt.month, dt.day] + TIME_EMPTY_TIME + TIME_EMPTY_EXTRAS
)
else:
raise NotImplementedError(f"Cannot convert {type(dt)} to `struct_time`")
raise NotImplementedError(f"Cannot convert {type(dt)} to `struct_time`")


def struct_time_to_date(st):
def struct_time_to_date(st: struct_time) -> date:
"""
Return a `datetime.date` representing the provided `struct_time.

Expand All @@ -52,7 +51,7 @@ def struct_time_to_date(st):
return date(*st[:3])


def struct_time_to_datetime(st):
def struct_time_to_datetime(st: struct_time) -> datetime:
"""
Return a `datetime.datetime` representing the provided `struct_time.

Expand All @@ -61,7 +60,7 @@ def struct_time_to_datetime(st):
return datetime(*st[:6])


def trim_struct_time(st, strip_time=False):
def trim_struct_time(st: struct_time, strip_time: bool = False) -> struct_time:
"""
Return a `struct_time` based on the one provided but with the extra fields
`tm_wday`, `tm_yday`, and `tm_isdst` reset to default values.
Expand All @@ -75,7 +74,7 @@ def trim_struct_time(st, strip_time=False):
return struct_time(list(st[:6]) + TIME_EMPTY_EXTRAS)


def struct_time_to_jd(st):
def struct_time_to_jd(st: struct_time) -> float:
"""
Return a float number representing the Julian Date for the given
`struct_time`.
Expand All @@ -91,7 +90,7 @@ def struct_time_to_jd(st):
return jdutil.date_to_jd(year, month, day)


def jd_to_struct_time(jd):
def jd_to_struct_time(jd: float) -> struct_time:
"""
Return a `struct_time` converted from a Julian Date float number.

Expand Down
16 changes: 8 additions & 8 deletions edtf/jdutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# time deltas if one date is from before 10-15-1582.


def mjd_to_jd(mjd):
def mjd_to_jd(mjd: float) -> float:
"""
Convert Modified Julian Day to Julian Day.

Expand All @@ -37,7 +37,7 @@ def mjd_to_jd(mjd):
return mjd + 2400000.5


def jd_to_mjd(jd):
def jd_to_mjd(jd: float) -> float:
"""
Convert Julian Day to Modified Julian Day

Expand All @@ -55,7 +55,7 @@ def jd_to_mjd(jd):
return jd - 2400000.5


def date_to_jd(year, month, day):
def date_to_jd(year: int, month: int, day: float) -> float:
"""
Convert a date to Julian Day.

Expand Down Expand Up @@ -117,7 +117,7 @@ def date_to_jd(year, month, day):
return jd


def jd_to_date(jd):
def jd_to_date(jd: float) -> tuple:
"""
Convert Julian Day to date.

Expand Down Expand Up @@ -175,7 +175,7 @@ def jd_to_date(jd):
return year, month, day


def hmsm_to_days(hour=0, min=0, sec=0, micro=0):
def hmsm_to_days(hour: int = 0, min: int = 0, sec: int = 0, micro: int = 0) -> float:
"""
Convert hours, minutes, seconds, and microseconds to fractional days.

Expand Down Expand Up @@ -262,7 +262,7 @@ def days_to_hmsm(days):
return int(hour), int(min), int(sec), int(micro)


def datetime_to_jd(date):
def datetime_to_jd(date: dt.datetime) -> float:
"""
Convert a `datetime.datetime` object to Julian Day.

Expand Down Expand Up @@ -291,7 +291,7 @@ def datetime_to_jd(date):
return date_to_jd(date.year, date.month, days)


def jd_to_datetime(jd):
def jd_to_datetime(jd: float) -> dt.datetime:
"""
Convert a Julian Day to an `jdutil.datetime` object.

Expand Down Expand Up @@ -321,7 +321,7 @@ def jd_to_datetime(jd):
return datetime(year, month, day, hour, min, sec, micro)


def timedelta_to_days(td):
def timedelta_to_days(td: dt.timedelta) -> float:
"""
Convert a `datetime.timedelta` object to a total number of days.

Expand Down
Loading