Skip to content

Commit 77f9e39

Browse files
authored
Improve repr string representation of Duration and ClockTime (#1235)
1 parent 6a98a8e commit 77f9e39

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
196196
- Adjust string representation(s) of several types:
197197
- `SummaryCounters`: `repr` and `str` to conform with Python's recommendations.
198198
- `Point` and its subclasses: `repr` to conform with Python's recommendations.
199+
- `Duration` and `ClockTime`: `repr` to be more consistent with other temporal driver types.
199200

200201

201202
## Version 5.28

src/neo4j/time/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def __sub__(self, other):
274274

275275
def __repr__(self):
276276
s, ns = self
277-
return f"ClockTime(seconds={s!r}, nanoseconds={ns!r})"
277+
return f"neo4j.time.ClockTime(seconds={s!r}, nanoseconds={ns!r})"
278278

279279
@property
280280
def seconds(self):
@@ -655,8 +655,12 @@ def __abs__(self) -> Duration:
655655
def __repr__(self) -> str:
656656
mo, day, sec, ns = self
657657
return (
658-
f"Duration(months={mo!r}, days={day!r}, seconds={sec!r}, "
659-
f"nanoseconds={ns!r})"
658+
"neo4j.time.Duration("
659+
f"months={mo!r}, "
660+
f"days={day!r}, "
661+
f"seconds={sec!r}, "
662+
f"nanoseconds={ns!r}"
663+
")"
660664
)
661665

662666
def __str__(self) -> str:

tests/unit/common/time/test_clocktime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ def test_sub_object(self):
9696

9797
def test_repr(self):
9898
ct = _ClockTime(123456.789)
99-
assert repr(ct).startswith("ClockTime")
99+
assert repr(ct).startswith("neo4j.time.ClockTime")

tests/unit/common/time/test_duration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ def test_str(self) -> None:
356356
def test_repr(self) -> None:
357357
d = Duration(months=2, days=3, seconds=5.7)
358358
assert repr(d) == (
359-
"Duration(months=2, days=3, seconds=5, nanoseconds=700000000)"
359+
"neo4j.time.Duration("
360+
"months=2, days=3, seconds=5, nanoseconds=700000000"
361+
")"
360362
)
361363

362364
def test_iso_format(self) -> None:

0 commit comments

Comments
 (0)