Skip to content

Commit

Permalink
Cleanup unnecessary code (py-libhdate#126)
Browse files Browse the repository at this point in the history
* cleanup: Removal of BaseClass

* Split location and hebrew date, remove tests_common
  • Loading branch information
tsvi committed Jun 20, 2024
1 parent ea85050 commit 11f4a7e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 89 deletions.
3 changes: 2 additions & 1 deletion hdate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
of the Jewish calendrical date and times for a given location
"""

from hdate.common import HebrewDate, Location
from hdate.date import HDate
from hdate.hebrew_date import HebrewDate
from hdate.htables import HolidayTypes
from hdate.location import Location
from hdate.zmanim import Zmanim

__all__ = ["HDate", "Zmanim", "HebrewDate", "Location", "HolidayTypes"]
2 changes: 1 addition & 1 deletion hdate/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import datetime

from hdate.common import HebrewDate
from hdate.hebrew_date import HebrewDate
from hdate.htables import Months


Expand Down
4 changes: 2 additions & 2 deletions hdate/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

from hdate import converters as conv
from hdate import htables
from hdate.common import BaseClass, HebrewDate
from hdate.hebrew_date import HebrewDate
from hdate.htables import HolidayTypes, Months

_LOGGER = logging.getLogger(__name__)
# pylint: disable=too-many-public-methods


class HDate(BaseClass):
class HDate:
"""
Hebrew date class.
Expand Down
19 changes: 19 additions & 0 deletions hdate/hebrew_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Pure Hebrew date class."""

from dataclasses import dataclass

from hdate.htables import Months


@dataclass
class HebrewDate:
"""Define a Hebrew date object."""

year: int
month: Months
day: int

def __post_init__(self):
self.month = (
self.month if isinstance(self.month, Months) else Months(self.month)
)
33 changes: 2 additions & 31 deletions hdate/common.py → hdate/location.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Small helper classes."""
"""Location data for HDate - used by Zmanim."""

from dataclasses import dataclass
from datetime import tzinfo
Expand All @@ -8,38 +8,9 @@
except ImportError:
from backports.zoneinfo import ZoneInfo

from hdate.htables import Months


class BaseClass:
"""Implement basic functionality for all classes."""

def __eq__(self, other):
"""Override equality operator."""
if isinstance(other, self.__class__):
return self.__dict__ == other.__dict__
return False

def __ne__(self, other):
"""Override inequality operator."""
return not self.__eq__(other)


@dataclass
class HebrewDate(BaseClass):
"""Define a Hebrew date object."""

year: int
month: Months
day: int

def __post_init__(self):
self.month = (
self.month if isinstance(self.month, Months) else Months(self.month)
)


class Location(BaseClass):
class Location:
"""Define a geolocation for Zmanim calculations."""

# pylint: disable=too-many-arguments
Expand Down
4 changes: 2 additions & 2 deletions hdate/zmanim.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import math

from hdate import htables
from hdate.common import BaseClass, Location
from hdate.date import HDate
from hdate.location import Location

try:
import astral
Expand All @@ -25,7 +25,7 @@
_LOGGER = logging.getLogger(__name__)


class Zmanim(BaseClass): # pylint: disable=too-many-instance-attributes
class Zmanim: # pylint: disable=too-many-instance-attributes
"""Return Jewish day times.
The Zmanim class returns times for the specified day ONLY. If you wish to
Expand Down
50 changes: 0 additions & 50 deletions tests/test_common.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from hdate import converters as conv
from hdate.common import HebrewDate
from hdate.hebrew_date import HebrewDate
from hdate.htables import Months


Expand Down
2 changes: 1 addition & 1 deletion tests/test_zmanim.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from backports.zoneinfo import ZoneInfo

from hdate import Zmanim
from hdate.common import Location
from hdate.location import Location

_ASTRAL = "astral" in sys.modules

Expand Down

0 comments on commit 11f4a7e

Please sign in to comment.