Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make YearMonth immutable #11

Merged
merged 2 commits into from Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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