Skip to content

Commit 970b036

Browse files
author
Mauko Quiroga
committed
Add doc to period class
1 parent 864241f commit 970b036

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

openfisca_core/periods/period_.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import calendar
44

5-
from openfisca_core import periods
5+
from openfisca_core.periods import Instant
66

77
from .date_unit import DateUnit
88

@@ -15,20 +15,24 @@ class Period(tuple):
1515
(year, month, day) triple, and where size is an integer > 1.
1616
1717
Since a period is a triple it can be used as a dictionary key.
18+
19+
Examples:
20+
>>> instant = Instant((2021, 9, 1))
21+
>>> period = Period((DateUnit.YEAR.value, instant, 3))
22+
23+
>>> repr(Period)
24+
"<class 'openfisca_core.periods.period_.Period'>"
25+
26+
>>> repr(period)
27+
"<Period(('year', <Instant(2021, 9, 1)>, 3))>"
28+
29+
>>> str(period)
30+
'year:2021-09:3'
31+
1832
"""
1933

20-
def __repr__(self):
21-
"""
22-
Transform period to to its Python representation as a string.
23-
24-
>>> repr(period('year', 2014))
25-
"Period(('year', Instant((2014, 1, 1)), 1))"
26-
>>> repr(period('month', '2014-2'))
27-
"Period(('month', Instant((2014, 2, 1)), 1))"
28-
>>> repr(period('day', '2014-2-3'))
29-
"Period(('day', Instant((2014, 2, 3)), 1))"
30-
"""
31-
return '{}({})'.format(self.__class__.__name__, super(Period, self).__repr__())
34+
def __repr__(self) -> str:
35+
return f"<{self.__class__.__name__}({super().__repr__()})>"
3236

3337
def __str__(self):
3438
"""

0 commit comments

Comments
 (0)