diff --git a/openfisca_core/periods/period_.py b/openfisca_core/periods/period_.py index 707bc43c0e..7411d9f72c 100644 --- a/openfisca_core/periods/period_.py +++ b/openfisca_core/periods/period_.py @@ -121,42 +121,10 @@ class Period(tuple): """ - def __repr__(self): + def __repr__(self) -> str: return '{}({})'.format(self.__class__.__name__, super(Period, self).__repr__()) - def __str__(self): - """Transform period to a string. - - Examples: - >>> str(Period(("year", Instant((2021, 1, 1)), 1))) - '2021' - - >>> str(Period(("year", Instant((2021, 2, 1)), 1))) - 'year:2021-02' - - >>> str(Period(("month", Instant((2021, 2, 1)), 1))) - '2021-02' - - >>> str(Period(("year", Instant((2021, 1, 1)), 2))) - 'year:2021:2' - - >>> str(Period(("month", Instant((2021, 1, 1)), 2))) - 'month:2021-01:2' - - >>> str(Period(("month", Instant((2021, 1, 1)), 12))) - '2021' - - >>> str(Period(("year", Instant((2021, 3, 1)), 2))) - 'year:2021-03:2' - - >>> str(Period(("month", Instant((2021, 3, 1)), 2))) - 'month:2021-03:2' - - >>> str(Period(("month", Instant((2021, 3, 1)), 12))) - 'year:2021-03' - - """ - + def __str__(self) -> str: unit, start_instant, size = self if unit == config.ETERNITY: return 'ETERNITY' diff --git a/openfisca_core/periods/tests/period/test_str.py b/openfisca_core/periods/tests/period/test_str.py index 47ea3c390d..874a8405ab 100644 --- a/openfisca_core/periods/tests/period/test_str.py +++ b/openfisca_core/periods/tests/period/test_str.py @@ -30,4 +30,4 @@ def test_str_with_months(date_unit, instant, size, expected): [DateUnit.DAY, Instant((2022, 3, 1)), 3, "day:2022-03-01:3"], ]) def test_str_with_days(date_unit, instant, size, expected): - assert str(Period((date_unit, instant, size))) == expected \ No newline at end of file + assert str(Period((date_unit, instant, size))) == expected diff --git a/tests/core/test_periods.py b/tests/core/test_periods.py index 92c8b49022..58fffd7919 100644 --- a/tests/core/test_periods.py +++ b/tests/core/test_periods.py @@ -15,6 +15,7 @@ # Years + def test_parsing_year(): assert period('2014') == Period((YEAR, first_jan, 1))