Skip to content

Commit

Permalink
fix: update param name for type input in dateparse
Browse files Browse the repository at this point in the history
  • Loading branch information
seandstewart committed Jul 31, 2024
1 parent 5d9d07d commit 1779b4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/typelib/serdes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import contextlib
import dataclasses
import datetime
import functools
import operator
import typing as t

Expand Down Expand Up @@ -199,7 +198,7 @@ def unixtime(dt: datetime.date | datetime.time | datetime.timedelta) -> float:


@compat.lru_cache(maxsize=100_000)
def dateparse(val: str, td: type[DateTimeT]) -> DateTimeT:
def dateparse(val: str, t: type[DateTimeT]) -> DateTimeT:
"""Parse a date string into a datetime object.
Examples:
Expand All @@ -210,23 +209,24 @@ def dateparse(val: str, td: type[DateTimeT]) -> DateTimeT:
Args:
val: The date string to parse.
td: The target datetime type.
t: The target datetime type.
Returns:
The parsed datetime object.
Raises:
ValueError: If `val` is not a date string or does not resolve to an instance of
the target datetime type.
ValueError:
If `val` is not a date string or does not resolve to an instance of
the target datetime type.
"""
try:
# When `exact=False`, the only two possibilities are DateTime and Duration.
parsed: pendulum.DateTime | pendulum.Duration = pendulum.parse(val) # type: ignore[assignment]
normalized = _nomalize_dt(val=val, parsed=parsed, td=td)
normalized = _nomalize_dt(val=val, parsed=parsed, td=t)
return normalized
except ValueError:
if val.isdigit() or val.isdecimal():
return _normalize_number(numval=float(val), td=td)
return _normalize_number(numval=float(val), td=t)
raise


Expand Down
2 changes: 1 addition & 1 deletion src/typelib/unmarshal/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def __call__(self, val: tp.Any) -> TimeDeltaT:

decoded = serdes.decode(val)
td: datetime.timedelta = (
serdes.dateparse(decoded, td=datetime.timedelta)
serdes.dateparse(decoded, t=datetime.timedelta)
if isinstance(decoded, str)
else decoded
)
Expand Down

0 comments on commit 1779b4e

Please sign in to comment.