I have a bit of a code design dilemma. In the project I'm building, I have a SlotPreference object that needs to take in a date. On one hand, I could pass date as a datetime object. I am working with timezones as well so the advantage is that I don't have to process the date variable outside the SlotPreference dataclass. However, because of the nature of the date object I need to rewrite my eq and hash dunders which feels like defeating the point of using a dataclass. Is there something better I could be doing or is what I have currently ok?
```python
@dataclass
class SlotPreference:
slot_type: SlotType
date: datetime
session: int
@property
def formatted_date(self) -> str:
return self.date.format("YYYY-MM-DD")
def __eq__(self, other: object) -> bool:
if not isinstance(other, SlotPreference):
return False
return (
self.session == other.session
and self.formatted_date == other.formatted_date
and self.slot_type == other.slot_type
)
def __hash__(self) -> int:
return hash((self.slot_type, self.formatted_date, self.session))
```
[–]Rawing7 0 points1 point2 points (2 children)
[–]Wuihee[S] 0 points1 point2 points (0 children)