diff --git a/CHANGELOG.md b/CHANGELOG.md index cad8eb9..9fcd3a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## v0.4.0 + +### Changed + +- Made `YearMonth` instances immutable. + ## v0.3.1 ### Changed diff --git a/mp_yearmonth/yearmonth.py b/mp_yearmonth/yearmonth.py index cd2c3c0..b0852f6 100644 --- a/mp_yearmonth/yearmonth.py +++ b/mp_yearmonth/yearmonth.py @@ -41,7 +41,7 @@ class YearMonth: month (int) : The month. """ - __slots__ = ("year", "month") + __slots__ = ("_year", "_month") def __init__(self, year: int, month: int): """Create a new YearMonth object. @@ -63,8 +63,8 @@ def __init__(self, year: int, month: int): f"year must be between {datetime.MINYEAR} and {datetime.MAXYEAR}" ) - self.year = year - self.month = month + self._year = year + self._month = month def __str__(self): return self.iso8601 @@ -117,6 +117,16 @@ def __contains__(self, other) -> bool: # Public interface + @property + def year(self) -> int: + """The year.""" + return self._year + + @property + def month(self) -> int: + """The month.""" + return self._month + @property def iso8601(self) -> str: """The ISO 8601 representation of the year and month.""" diff --git a/pyproject.toml b/pyproject.toml index 1500082..c8a1cca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mp-yearmonth" -version = "0.3.1" +version = "0.4.0" description = "A year-month datatype for Python." keywords = ["year", "month", "date", "calendar"] authors = ["Ramon Torres "]