Skip to content

Commit

Permalink
Make YearMonth immutable (#11)
Browse files Browse the repository at this point in the history
* Made YearMonth immutable

* Update CHANGELOG
  • Loading branch information
raymondjavaxx committed Mar 9, 2024
1 parent 237b881 commit 7567e75
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions mp_yearmonth/yearmonth.py
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion 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 <ramon@macropoetry.com>"]
Expand Down

0 comments on commit 7567e75

Please sign in to comment.