Skip to content

Commit 6098361

Browse files
committed
Minor cleanup and fixes suggested by coderabbitai
1 parent 04f8b65 commit 6098361

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
- Dropped support for Python 3.9
2020
- Reorganized examples folder to avoid unnecessary nesting
2121
- ISMI data has been updated from older JSON data to examples in RDF (turtle)
22-
-
2322

2423

2524
## 0.3.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ portions of EDTF (Extended Date Time Format), and parsing and conversion for dat
1111

1212
*Undate was initially created as part of a [DH-Tech](https://dh-tech.github.io/) hackathon in November 2022.*
1313

14-
---
14+
* * *
1515

1616
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.11068867.svg)](https://doi.org/10.5281/zenodo.11068867)
1717
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

src/undate/interval.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def duration(self) -> Timedelta:
9494

9595
# if range is open-ended, can't calculate
9696
if self.earliest is None or self.latest is None:
97-
return NotImplemented
97+
raise NotImplementedError(
98+
"Cannot calculate duration for open-ended interval"
99+
)
98100

99101
# if both years are known, subtract end of range from beginning of start
100102
if self.latest.known_year and self.earliest.known_year:

src/undate/undate.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ def set_calendar(self, calendar: Union[str, Calendar]):
198198
# look for calendar by upper-case name
199199
try:
200200
calendar = Calendar[calendar.upper()]
201-
except KeyError:
202-
raise ValueError(f"Calendar `{calendar}` is not supported")
201+
except KeyError as err:
202+
raise ValueError(f"Calendar `{calendar}` is not supported") from err
203203
self.calendar = calendar
204204

205205
def __str__(self) -> str:
@@ -292,15 +292,13 @@ def __eq__(self, other: object) -> bool:
292292
# in one format (i.e. X for missing digits).
293293
# If we support other formats, will need to normalize to common
294294
# internal format for comparison
295-
if looks_equal:
295+
if looks_equal and (
296296
# if any part of either date that is known is _partially_ known,
297297
# then these dates are not equal
298-
if any(
299-
[self.is_partially_known(p) for p in self.initial_values.keys()]
300-
) or any(
301-
[other.is_partially_known(p) for p in other.initial_values.keys()]
302-
):
303-
return False
298+
any([self.is_partially_known(p) for p in self.initial_values.keys()])
299+
or any([other.is_partially_known(p) for p in other.initial_values.keys()])
300+
):
301+
return False
304302

305303
return looks_equal
306304

tests/test_converters/test_calendars/test_islamic/test_islamic_parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import pytest
2+
from lark.exceptions import LarkError
3+
24
from undate.converters.calendars.islamic.parser import islamic_parser
35

46

@@ -72,5 +74,5 @@ def test_should_parse(date_string):
7274

7375
@pytest.mark.parametrize("date_string", error_cases)
7476
def test_should_error(date_string):
75-
with pytest.raises(Exception):
77+
with pytest.raises(LarkError):
7678
islamic_parser.parse(date_string)

tests/test_interval.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ def test_duration(self):
144144
assert jan_march_duration.days == 2
145145

146146
# duration is not supported for open-ended intervals
147-
assert UndateInterval(Undate(2000), None).duration() == NotImplemented
147+
with pytest.raises(
148+
NotImplementedError, match="Cannot calculate.*open-ended interval"
149+
):
150+
assert UndateInterval(Undate(2000), None).duration()
148151

149152
# one year set and the other not currently raises not implemented error
150153
with pytest.raises(NotImplementedError):

0 commit comments

Comments
 (0)