Skip to content

Commit

Permalink
Add doc to period class
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauko Quiroga committed Sep 17, 2021
1 parent 864241f commit 970b036
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions openfisca_core/periods/period_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import calendar

from openfisca_core import periods
from openfisca_core.periods import Instant

from .date_unit import DateUnit

Expand All @@ -15,20 +15,24 @@ class Period(tuple):
(year, month, day) triple, and where size is an integer > 1.
Since a period is a triple it can be used as a dictionary key.
Examples:
>>> instant = Instant((2021, 9, 1))
>>> period = Period((DateUnit.YEAR.value, instant, 3))
>>> repr(Period)
"<class 'openfisca_core.periods.period_.Period'>"
>>> repr(period)
"<Period(('year', <Instant(2021, 9, 1)>, 3))>"
>>> str(period)
'year:2021-09:3'
"""

def __repr__(self):
"""
Transform period to to its Python representation as a string.
>>> repr(period('year', 2014))
"Period(('year', Instant((2014, 1, 1)), 1))"
>>> repr(period('month', '2014-2'))
"Period(('month', Instant((2014, 2, 1)), 1))"
>>> repr(period('day', '2014-2-3'))
"Period(('day', Instant((2014, 2, 3)), 1))"
"""
return '{}({})'.format(self.__class__.__name__, super(Period, self).__repr__())
def __repr__(self) -> str:
return f"<{self.__class__.__name__}({super().__repr__()})>"

def __str__(self):
"""
Expand Down

0 comments on commit 970b036

Please sign in to comment.