Skip to content

Commit f06960a

Browse files
committed
Use raise from err on type error in interval init
Based on @coderabbitai feedback
1 parent 4504542 commit f06960a

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/undate/interval.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ def __init__(
3636
if earliest:
3737
try:
3838
earliest = Undate.to_undate(earliest)
39-
except TypeError:
39+
except TypeError as err:
4040
raise ValueError(
4141
f"earliest date {earliest} cannot be converted to Undate"
42-
)
42+
) from err
4343
if latest:
4444
try:
4545
latest = Undate.to_undate(latest)
46-
except TypeError:
47-
raise ValueError(f"latest date {latest} cannot be converted to Undate")
46+
except TypeError as err:
47+
raise ValueError(
48+
f"latest date {latest} cannot be converted to Undate"
49+
) from err
4850

4951
# check that the interval is valid
5052
if latest and earliest and latest <= earliest:
@@ -123,7 +125,7 @@ def duration(self) -> Timedelta:
123125

124126
def intersection(self, other: "UndateInterval") -> Optional["UndateInterval"]:
125127
"""Determine the intersection or overlap between two :class:`UndateInterval`
126-
objects and return a new interval, or None if no overlap.
128+
objects and return a new interval. Returns None if there is no overlap.
127129
"""
128130
try:
129131
# when both values are defined, return the inner bounds;

0 commit comments

Comments
 (0)