Skip to content

Commit

Permalink
Inline single-use variables, update .py files formatting (#2161)
Browse files Browse the repository at this point in the history
  • Loading branch information
KJhellico authored Dec 10, 2024
1 parent 5f37ecc commit ced9ee7
Show file tree
Hide file tree
Showing 40 changed files with 146 additions and 277 deletions.
47 changes: 22 additions & 25 deletions holidays/countries/angola.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _add_observed(self, dt: date, **kwargs) -> tuple[bool, Optional[date]]:

def _populate_public_holidays(self):
# New Year's Day.
name = self.tr("Dia do Ano Novo")
name = tr("Dia do Ano Novo")
dt = self._add_new_years_day(name)
if self._year <= 2011 or self._year >= 2018:
self._add_observed(dt)
Expand All @@ -84,14 +84,15 @@ def _populate_public_holidays(self):
self._add_holiday_jan_4(tr("Dia dos Mártires da Repressão Colonial"))
)

name = (
# Beginning of the Armed Struggle for National Liberation Day.
tr("Dia do Início da Luta Armada de Libertação Nacional")
if self._year >= 2012
# Beginning of the Armed Struggle Day.
else tr("Dia do Início da Luta Armada")
self._add_observed(
self._add_holiday_feb_4(
# Beginning of the Armed Struggle for National Liberation Day.
tr("Dia do Início da Luta Armada de Libertação Nacional")
if self._year >= 2012
# Beginning of the Armed Struggle Day.
else tr("Dia do Início da Luta Armada")
)
)
self._add_observed(self._add_holiday_feb_4(name))

# Law #16/96.
if self._year >= 1997:
Expand All @@ -103,17 +104,13 @@ def _populate_public_holidays(self):

# Law #11/18.
if self._year >= 2019:
self._add_observed(
# Southern Africa Liberation Day.
self._add_holiday_mar_23(tr("Dia da Libertação da África Austral"))
)
# Southern Africa Liberation Day.
self._add_observed(self._add_holiday_mar_23(tr("Dia da Libertação da África Austral")))

# Law #7/03.
if self._year >= 2003:
self._add_observed(
# Peace and National Reconciliation Day.
self._add_holiday_apr_4(tr("Dia da Paz e Reconciliação Nacional"))
)
# Peace and National Reconciliation Day.
self._add_observed(self._add_holiday_apr_4(tr("Dia da Paz e Reconciliação Nacional")))

# Law #16/96.
if self._year >= 1997:
Expand Down Expand Up @@ -145,21 +142,22 @@ def _populate_public_holidays(self):
if self._year <= 2010 or self._year >= 2018:
self._add_observed(dt)

name = (
# National Independence Day.
tr("Dia da Independência Nacional")
if self._year >= 1996
# Independence Day.
else tr("Dia da Independência")
self._add_observed(
self._add_holiday_nov_11(
# National Independence Day.
tr("Dia da Independência Nacional")
if self._year >= 1996
# Independence Day.
else tr("Dia da Independência")
)
)
self._add_observed(self._add_holiday_nov_11(name))

# Decree # 7/92.
if self._year <= 1991:
# Date of Founding of MPLA - Labor Party.
self._add_holiday_dec_10(tr("Data da Fundacao do MPLA - Partido do Trabalho"))

name = (
dt = self._add_christmas_day(
# Christmas and Family Day.
tr("Dia de Natal e da Família")
if self._year >= 2011
Expand All @@ -169,7 +167,6 @@ def _populate_public_holidays(self):
else tr("Dia da Família") # Family Day.
)
)
dt = self._add_christmas_day(name)
if self._year <= 2010 or self._year >= 2018:
self._add_observed(dt)

Expand Down
5 changes: 2 additions & 3 deletions holidays/countries/argentina.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _populate_public_holidays(self):
if self._year >= 2016:
jun_17 = self._add_holiday_jun_17(
# Pass to the Immortality of General Don Martin Miguel de Guemes.
tr("Paso a la Inmortalidad del General Don Martín Miguel de Güemes"),
tr("Paso a la Inmortalidad del General Don Martín Miguel de Güemes")
)
# If Jun 17 is Friday, then it should move to Mon, Jun 20
# but Jun 20 is Gen. Belgrano holiday
Expand All @@ -232,14 +232,13 @@ def _populate_public_holidays(self):
# In 2010 the holiday became movable and its name was changed.

if self._year >= 1917:
name = (
oct_12 = self._add_columbus_day(
# Respect for Cultural Diversity Day.
tr("Día del Respeto a la Diversidad Cultural")
if self._year >= 2010
# Columbus Day.
else tr("Día de la Raza")
)
oct_12 = self._add_columbus_day(name)
if self._year >= 2010:
self._move_holiday(oct_12)

Expand Down
2 changes: 1 addition & 1 deletion holidays/countries/bolivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _populate_public_holidays(self):
self._add_good_friday(tr("Viernes Santo"))

# Labor Day.
self._add_observed(may_1 := self._add_labor_day(self.tr("Día del Trabajo")))
self._add_observed(may_1 := self._add_labor_day(tr("Día del Trabajo")))
# Supreme Decree #1210.
if 2012 <= self._year <= 2015:
self._add_observed(may_1, rule=TUE_TO_PREV_MON + THU_TO_NEXT_FRI)
Expand Down
2 changes: 1 addition & 1 deletion holidays/countries/bosnia_and_herzegovina.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _populate_subdiv_srp_public_holidays(self):

self._add_holiday_nov_21(
# Dayton Agreement Day.
tr("Dan uspostave Opšteg okvirnog sporazuma za mir u Bosni i Hercegovini"),
tr("Dan uspostave Opšteg okvirnog sporazuma za mir u Bosni i Hercegovini")
)

# Catholic Christmas Eve.
Expand Down
13 changes: 6 additions & 7 deletions holidays/countries/cambodia.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _populate_public_holidays(self):
# NORODOM SIHAMONI, King of Cambodia
"ព្រះរាជពិធីបុណ្យចម្រើនព្រះជន្ម ព្រះករុណា ព្រះបាទសម្តេចព្រះបរមនាថ នរោត្តម សីហមុនី"
)
dt = self._add_holiday_may_14(king_sihamoni_bday)
self._add_holiday_may_14(king_sihamoni_bday)
if self._year <= 2019:
self._add_holiday_may_13(king_sihamoni_bday)
self._add_holiday_may_15(king_sihamoni_bday)
Expand Down Expand Up @@ -159,7 +159,7 @@ def _populate_public_holidays(self):
if self._year >= 1994:
self._add_holiday_jun_18(
# Birthday of Her Majesty the Queen-Mother NORODOM MONINEATH SIHANOUK of Cambodia
tr("ព្រះរាជពិធីបុណ្យចម្រើនព្រះជន្ម សម្តេចព្រះមហាក្សត្រី ព្រះវររាជមាតា នរោត្តម មុនិនាថ សីហនុ"),
tr("ព្រះរាជពិធីបុណ្យចម្រើនព្រះជន្ម សម្តេចព្រះមហាក្សត្រី ព្រះវររាជមាតា នរោត្តម មុនិនាថ សីហនុ")
)

# ទិវាប្រកាសរដ្ឋធម្មនុញ្ញ
Expand All @@ -176,13 +176,12 @@ def _populate_public_holidays(self):

if self._year >= 2012:
self._add_holiday_oct_15(
# Mourning Day of the Late King-Father
# NORODOM SIHANOUK of Cambodia
# Mourning Day of the Late King-Father NORODOM SIHANOUK of Cambodia
tr(
"ទិវាប្រារព្ឋពិធីគោរពព្រះវិញ្ញាណក្ខន្ឋ ព្រះករុណា ព្រះបាទសម្តេចព្រះ នរោត្តម "
"សីហនុ ព្រះមហាវីរក្សត្រ ព្រះវររាជបិតាឯករាជ្យ បូរណភាពទឹកដី និងឯកភាពជាតិខ្មែរ "
"ព្រះបរមរតនកោដ្ឋ"
),
)
)

# ទិវារំលឹកសន្ធិសញ្ញាសន្តិភាពទីក្រុងប៉ារីស
Expand All @@ -207,7 +206,7 @@ def _populate_public_holidays(self):
"ព្រះរាជពិធីគ្រងព្រះបរមរាជសម្បត្តិ របស់ ព្រះករុណា "
"ព្រះបាទសម្តេចព្រះបរមនាថ នរោត្តម សីហមុនី "
"ព្រះមហាក្សត្រនៃព្រះរាជាណាចក្រកម្ពុជា"
),
)
)

# ពិធីបុណ្យឯករាជ្យជាតិ
Expand All @@ -226,7 +225,7 @@ def _populate_public_holidays(self):
self._add_holiday_dec_10(tr("ទិវាសិទ្ធិមនុស្សអន្តរជាតិ"))

# Cambodian Lunar Calendar Holidays
# See `_ThaiLunisolar` in holidays/utils.py for more details.
# See `_ThaiLunisolar` in holidays/calendars/thai.py for more details.
# Cambodian Lunar Calendar Holidays only work from 1941 to 2157.

# ពិធីបុណ្យមាឃបូជា
Expand Down
3 changes: 1 addition & 2 deletions holidays/countries/canada.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,13 @@ def _populate_subdiv_mb_public_holidays(self):

def _populate_subdiv_mb_optional_holidays(self):
if self._year >= 1900:
name = (
self._add_holiday_1st_mon_of_aug(
# Terry Fox Day.
tr("Terry Fox Day")
if self._year >= 2015
# Civic Holiday.
else tr("Civic Holiday")
)
self._add_holiday_1st_mon_of_aug(name)

if self._year >= 1931:
# Remembrance Day.
Expand Down
21 changes: 10 additions & 11 deletions holidays/countries/chile.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ def _populate_public_holidays(self):
# Day of National Liberation.
self._add_holiday_sep_11(tr("Día de la Liberación Nacional"))
elif 1999 <= self._year <= 2001:
self._add_holiday_1st_mon_of_sep(
# Day of National Unity.
tr("Día de la Unidad Nacional")
)
# Day of National Unity.
self._add_holiday_1st_mon_of_sep(tr("Día de la Unidad Nacional"))

if self._year >= 2007:
self._add_observed(
Expand All @@ -168,14 +166,15 @@ def _populate_public_holidays(self):
self._add_holiday_sep_20(tr("Fiestas Patrias"))

if self._year >= 1922 and self._year != 1973:
name = (
# Meeting of Two Worlds' Day.
tr("Día del Encuentro de dos Mundos")
if self._year >= 2000
# Columbus Day.
else tr("Día de la Raza")
self._move_holiday(
self._add_columbus_day(
# Meeting of Two Worlds' Day.
tr("Día del Encuentro de dos Mundos")
if self._year >= 2000
# Columbus Day.
else tr("Día de la Raza")
)
)
self._move_holiday(self._add_columbus_day(name))

if self._year >= 2008:
# This holiday is moved to the preceding Friday if it falls on a Tuesday,
Expand Down
2 changes: 1 addition & 1 deletion holidays/countries/costa_rica.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _populate_optional_holidays(self):
if self._year >= 2021:
aug_31 = self._add_holiday_aug_31(
# Day of the Black Person and Afro-Costa Rican Culture.
self.tr("Día de la Persona Negra y la Cultura Afrocostarricense")
tr("Día de la Persona Negra y la Cultura Afrocostarricense")
)
if self._year in {2021, 2022, 2023}:
# Move to next Sunday.
Expand Down
3 changes: 1 addition & 2 deletions holidays/countries/croatia.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ def _populate_public_holidays(self):
# Anti-Fascist Struggle Day.
self._add_holiday_jun_22(tr("Dan antifašističke borbe"))

name = (
self._add_holiday_aug_5(
# Victory and Homeland Thanksgiving Day and Croatian Veterans Day.
tr("Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja")
if self._year >= 2008
# Victory and Homeland Thanksgiving Day.
else tr("Dan pobjede i domovinske zahvalnosti")
)
self._add_holiday_aug_5(name)

# Assumption Day.
self._add_assumption_of_mary_day(tr("Velika Gospa"))
Expand Down
2 changes: 1 addition & 1 deletion holidays/countries/czechia.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _populate_public_holidays(self):
tr("Den obnovy samostatného českého státu")
if self._year >= 2000
# New Year's Day.
else tr("Nový rok"),
else tr("Nový rok")
)

if self._year <= 1951 or self._year >= 2016:
Expand Down
3 changes: 1 addition & 2 deletions holidays/countries/dominica.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@ def _populate_public_holidays(self):
# Whit Monday.
self._add_whit_monday("Whit Monday")

first_monday_of_august_holiday_name = (
self._add_holiday_1st_mon_of_aug(
# Emancipation Day.
"Emancipation Day"
if self._year >= 1998
# First Monday of August.
else "First Monday of August"
)
self._add_holiday_1st_mon_of_aug(first_monday_of_august_holiday_name)

# Independence Day.
self._add_observed(self._add_holiday_nov_3("Independence Day"), rule=SUN_TO_NEXT_TUE)
Expand Down
4 changes: 2 additions & 2 deletions holidays/countries/hungary.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, *args, **kwargs):

def _populate_public_holidays(self):
# New Year's Day.
self._add_new_years_day(self.tr("Újév"))
self._add_new_years_day(tr("Újév"))

if 1945 <= self._year <= 1950 or self._year >= 1989:
# National Day.
Expand Down Expand Up @@ -90,7 +90,7 @@ def _populate_public_holidays(self):
tr("A kenyér ünnepe")
if 1950 <= self._year <= 1989
# State Foundation Day.
else tr("Az államalapítás ünnepe"),
else tr("Az államalapítás ünnepe")
)

if self._year >= 1991:
Expand Down
5 changes: 2 additions & 3 deletions holidays/countries/israel.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ def _populate_public_holidays(self):
# Yom Kippur (Day of Atonement).
self._add_holiday(tr("יום כיפור"), self._get_holiday(YOM_KIPPUR))

# Sukkot (Feast of Tabernacles).
name = tr("סוכות")
sukkot_dt = self._get_holiday(SUKKOT)
self._add_holiday(name, sukkot_dt)
# Sukkot (Feast of Tabernacles).
self._add_holiday(tr("סוכות"), sukkot_dt)
# Simchat Torah / Shemini Atzeret.
self._add_holiday(tr("שמחת תורה/שמיני עצרת"), _timedelta(sukkot_dt, +7))

Expand Down
6 changes: 2 additions & 4 deletions holidays/countries/latvia.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ def _populate_public_holidays(self):
self._add_labor_day(tr("Darba svētki"))

if self._year >= 2002:
dt = self._add_holiday_may_4(
# Restoration of Independence Day.
tr("Latvijas Republikas Neatkarības atjaunošanas diena")
)
# Restoration of Independence Day.
dt = self._add_holiday_may_4(tr("Latvijas Republikas Neatkarības atjaunošanas diena"))
if self._year >= 2008:
self._add_observed(dt)

Expand Down
2 changes: 1 addition & 1 deletion holidays/countries/lithuania.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _populate_public_holidays(self) -> None:
tr(
"Valstybės (Lietuvos karaliaus Mindaugo karūnavimo) "
"ir Tautiškos giesmės diena"
),
)
)

# Assumption Day.
Expand Down
2 changes: 1 addition & 1 deletion holidays/countries/namibia.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _populate_public_holidays(self):
self._add_holiday_sep_10(
"Day of the Namibian Women and International Human Rights Day"
if self._year >= 2005
else "International Human Rights Day",
else "International Human Rights Day"
)
)

Expand Down
11 changes: 3 additions & 8 deletions holidays/countries/new_zealand.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def _get_nearest_monday(self, *args) -> Optional[date]:
dt = args if len(args) > 1 else args[0]
dt = dt if isinstance(dt, date) else date(self._year, *dt)
return self._get_observed_date(dt, rule=ALL_TO_NEAREST_MON)
return self._get_observed_date(date(self._year, *args), rule=ALL_TO_NEAREST_MON)

def _populate_public_holidays(self):
# Bank Holidays Act 1873
Expand Down Expand Up @@ -256,12 +254,9 @@ def _populate_subdiv_nsn_public_holidays(self):

def _populate_subdiv_ntl_public_holidays(self):
if 1964 <= self._year <= 1973:
name = "Waitangi Day"
dt = (FEB, 6)
self._add_holiday("Waitangi Day", self._get_nearest_monday(FEB, 6))
else:
name = "Auckland Anniversary Day"
dt = (JAN, 29)
self._add_holiday(name, self._get_nearest_monday(dt))
self._add_holiday("Auckland Anniversary Day", self._get_nearest_monday(JAN, 29))

def _populate_subdiv_ota_public_holidays(self):
# there is no easily determined single day of local observance?!?!
Expand Down
4 changes: 2 additions & 2 deletions holidays/countries/philippines.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ class PhilippinesStaticHolidays:
(NOV, 2, additional_special),
(DEC, 24, additional_special),
),
2010: ((DEC, 24, additional_special),),
2012: ((NOV, 2, additional_special),),
2010: (DEC, 24, additional_special),
2012: (NOV, 2, additional_special),
2013: (
(NOV, 2, additional_special),
(DEC, 24, additional_special),
Expand Down
Loading

0 comments on commit ced9ee7

Please sign in to comment.