Skip to content

Commit

Permalink
Fix return type of parse_isodatetime
Browse files Browse the repository at this point in the history
parse_isodatetime had a return type that included None, inherited
from an earlier version of the function, but it raises an exception
if the provided string is not valid and can never return None. Fix
the return type to match.
  • Loading branch information
rra committed Feb 19, 2024
1 parent d17be2a commit 07d1945
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20240219_113514_rra_DM_42937.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Bug fixes

- Fix the return type of `safir.datetime.parse_isodatetime` to not include `None` since the function never returns `None`.
9 changes: 5 additions & 4 deletions src/safir/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ def isodatetime(timestamp: datetime) -> str:
return timestamp.strftime("%Y-%m-%dT%H:%M:%SZ")


def parse_isodatetime(time_string: str) -> datetime | None:
def parse_isodatetime(time_string: str) -> datetime:
"""Parse a string in a standard ISO date format.
Parameters
----------
time_string
Date and time formatted as an ISO 8601 date and time using ``Z`` as
the time zone. This is the same format produced by `isodatetime` and
the time zone. This is the same format produced by `isodatetime` and
is compatible with Kubernetes and the IVOA UWS standard.
Returns
Expand All @@ -134,8 +134,9 @@ def parse_isodatetime(time_string: str) -> datetime | None:
Notes
-----
When parsing input for a model, use `safir.pydantic.normalize_isodatetime`
instead of this function. Using a model will be the normal case; this
function is primarily useful in tests.
instead of this function. Using a model will be the normal case; this
function is primarily useful in tests or for the special parsing cases
required by the IVOA UWS standard.
"""
if not time_string.endswith("Z"):
raise ValueError(f"{time_string} does not end with Z")
Expand Down

0 comments on commit 07d1945

Please sign in to comment.