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

Satisfy mypy requirements #2053

Merged
merged 2 commits into from
Oct 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ repos:
exclude: ^(docs)

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.12.0
hooks:
- id: mypy
additional_dependencies:
Expand Down
16 changes: 10 additions & 6 deletions holidays/groups/buddhist.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, cls=None, show_estimated=False) -> None:
self._buddhist_calendar_show_estimated = show_estimated

def _add_buddhist_calendar_holiday(
self, name: str, dt_estimated: tuple[date, bool]
self, name: str, dt_estimated: tuple[Optional[date], bool]
) -> Optional[date]:
"""
Add Buddhist calendar holiday.
Expand All @@ -37,11 +37,15 @@ def _add_buddhist_calendar_holiday(
estimated_label = getattr(self, "estimated_label", "%s (estimated)")
dt, is_estimated = dt_estimated

return self._add_holiday(
self.tr(estimated_label) % self.tr(name)
if is_estimated and self._buddhist_calendar_show_estimated
else name,
dt,
return (
self._add_holiday(
self.tr(estimated_label) % self.tr(name)
if is_estimated and self._buddhist_calendar_show_estimated
else name,
dt,
)
if dt
else None
)

def _add_vesak(self, name) -> Optional[date]:
Expand Down
18 changes: 11 additions & 7 deletions holidays/groups/chinese.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _mid_autumn_festival(self):
return self._chinese_calendar.mid_autumn_date(self._year)[0]

def _add_chinese_calendar_holiday(
self, name: str, dt_estimated: tuple[date, bool], days_delta: int = 0
self, name: str, dt_estimated: tuple[Optional[date], bool], days_delta: int = 0
) -> Optional[date]:
"""
Add Chinese calendar holiday.
Expand All @@ -59,14 +59,18 @@ def _add_chinese_calendar_holiday(
estimated_label = getattr(self, "estimated_label", "%s (estimated)")
dt, is_estimated = dt_estimated

if days_delta != 0:
if days_delta and dt:
dt = _timedelta(dt, days_delta)

return self._add_holiday(
self.tr(estimated_label) % self.tr(name)
if is_estimated and self._chinese_calendar_show_estimated
else name,
dt,
return (
self._add_holiday(
self.tr(estimated_label) % self.tr(name)
if is_estimated and self._chinese_calendar_show_estimated
else name,
dt,
)
if dt
else None
)

def _add_chinese_birthday_of_buddha(self, name) -> Optional[date]:
Expand Down
16 changes: 10 additions & 6 deletions holidays/groups/hindu.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, cls=None, show_estimated=False) -> None:
self._hindu_calendar_show_estimated = show_estimated

def _add_hindu_calendar_holiday(
self, name: str, dt_estimated: tuple[date, bool]
self, name: str, dt_estimated: tuple[Optional[date], bool]
) -> Optional[date]:
"""
Add Hindu calendar holiday.
Expand All @@ -37,11 +37,15 @@ def _add_hindu_calendar_holiday(
estimated_label = getattr(self, "estimated_label", "%s (estimated)")
dt, is_estimated = dt_estimated

return self._add_holiday(
self.tr(estimated_label) % self.tr(name)
if is_estimated and self._hindu_calendar_show_estimated
else name,
dt,
return (
self._add_holiday(
self.tr(estimated_label) % self.tr(name)
if is_estimated and self._hindu_calendar_show_estimated
else name,
dt,
)
if dt
else None
)

def _add_diwali(self, name) -> Optional[date]:
Expand Down