Skip to content

Commit

Permalink
style(periods): fix linter errors (#1229)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Sep 26, 2024
1 parent 33f00cf commit d5ef321
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions openfisca_core/periods/period_.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class Period(tuple[t.DateUnit, t.Instant, int]):
"""

__slots__ = ()

def __repr__(self) -> str:
return f"{self.__class__.__name__}({super().__repr__()})"

Expand Down Expand Up @@ -466,11 +468,11 @@ def get_subperiods(self, unit: t.DateUnit) -> Sequence[t.Period]:
Examples:
>>> period = Period((DateUnit.YEAR, Instant((2021, 1, 1)), 1))
>>> period.get_subperiods(DateUnit.MONTH)
[Period((<DateUnit.MONTH: 'month'>, Instant((2021, 1, 1)), 1)),...2021, 12, 1)), 1))]
[Period((<DateUnit.MONTH: 'month'>, Instant((2021, 1, 1)), 1)),...]
>>> period = Period((DateUnit.YEAR, Instant((2021, 1, 1)), 2))
>>> period.get_subperiods(DateUnit.YEAR)
[Period((<DateUnit.YEAR: 'year'>, Instant((2021, 1, 1)), 1)),...((2022, 1, 1)), 1))]
[Period((<DateUnit.YEAR: 'year'>, Instant((2021, 1, 1)), 1)), P...]
"""
if helpers.unit_weight(self.unit) < helpers.unit_weight(unit):
Expand Down Expand Up @@ -513,39 +515,55 @@ def offset(self, offset: str | int, unit: t.DateUnit | None = None) -> t.Period:
>>> Period((DateUnit.DAY, Instant((2021, 1, 1)), 365)).offset(1)
Period((<DateUnit.DAY: 'day'>, Instant((2021, 1, 2)), 365))
>>> Period((DateUnit.DAY, Instant((2021, 1, 1)), 365)).offset(1, DateUnit.DAY)
>>> Period((DateUnit.DAY, Instant((2021, 1, 1)), 365)).offset(
... 1, DateUnit.DAY
... )
Period((<DateUnit.DAY: 'day'>, Instant((2021, 1, 2)), 365))
>>> Period((DateUnit.DAY, Instant((2021, 1, 1)), 365)).offset(1, DateUnit.MONTH)
>>> Period((DateUnit.DAY, Instant((2021, 1, 1)), 365)).offset(
... 1, DateUnit.MONTH
... )
Period((<DateUnit.DAY: 'day'>, Instant((2021, 2, 1)), 365))
>>> Period((DateUnit.DAY, Instant((2021, 1, 1)), 365)).offset(1, DateUnit.YEAR)
>>> Period((DateUnit.DAY, Instant((2021, 1, 1)), 365)).offset(
... 1, DateUnit.YEAR
... )
Period((<DateUnit.DAY: 'day'>, Instant((2022, 1, 1)), 365))
>>> Period((DateUnit.MONTH, Instant((2021, 1, 1)), 12)).offset(1)
Period((<DateUnit.MONTH: 'month'>, Instant((2021, 2, 1)), 12))
>>> Period((DateUnit.MONTH, Instant((2021, 1, 1)), 12)).offset(1, DateUnit.DAY)
>>> Period((DateUnit.MONTH, Instant((2021, 1, 1)), 12)).offset(
... 1, DateUnit.DAY
... )
Period((<DateUnit.MONTH: 'month'>, Instant((2021, 1, 2)), 12))
>>> Period((DateUnit.MONTH, Instant((2021, 1, 1)), 12)).offset(
... 1, DateUnit.MONTH
... )
Period((<DateUnit.MONTH: 'month'>, Instant((2021, 2, 1)), 12))
>>> Period((DateUnit.MONTH, Instant((2021, 1, 1)), 12)).offset(1, DateUnit.YEAR)
>>> Period((DateUnit.MONTH, Instant((2021, 1, 1)), 12)).offset(
... 1, DateUnit.YEAR
... )
Period((<DateUnit.MONTH: 'month'>, Instant((2022, 1, 1)), 12))
>>> Period((DateUnit.YEAR, Instant((2021, 1, 1)), 1)).offset(1)
Period((<DateUnit.YEAR: 'year'>, Instant((2022, 1, 1)), 1))
>>> Period((DateUnit.YEAR, Instant((2021, 1, 1)), 1)).offset(1, DateUnit.DAY)
>>> Period((DateUnit.YEAR, Instant((2021, 1, 1)), 1)).offset(
... 1, DateUnit.DAY
... )
Period((<DateUnit.YEAR: 'year'>, Instant((2021, 1, 2)), 1))
>>> Period((DateUnit.YEAR, Instant((2021, 1, 1)), 1)).offset(1, DateUnit.MONTH)
>>> Period((DateUnit.YEAR, Instant((2021, 1, 1)), 1)).offset(
... 1, DateUnit.MONTH
... )
Period((<DateUnit.YEAR: 'year'>, Instant((2021, 2, 1)), 1))
>>> Period((DateUnit.YEAR, Instant((2021, 1, 1)), 1)).offset(1, DateUnit.YEAR)
>>> Period((DateUnit.YEAR, Instant((2021, 1, 1)), 1)).offset(
... 1, DateUnit.YEAR
... )
Period((<DateUnit.YEAR: 'year'>, Instant((2022, 1, 1)), 1))
>>> Period((DateUnit.DAY, Instant((2011, 2, 28)), 1)).offset(1)
Expand Down

0 comments on commit d5ef321

Please sign in to comment.