Skip to content

Commit

Permalink
Class docstring will give its name
Browse files Browse the repository at this point in the history
I thought it was a bit sad that you had to give a `name` class property that was just for the sake of having a string to decribe the class. Describing the class means using a `docstring`.
Now the `name` property is deducted from the docstring, and all the Europe classes along with the "core" United States one are aligned with a more Pythonic way: a class should always have a docstring.
  • Loading branch information
brunobord committed Aug 30, 2018
1 parent dcf4a12 commit 8472fbb
Show file tree
Hide file tree
Showing 38 changed files with 141 additions and 55 deletions.
19 changes: 19 additions & 0 deletions workalendar/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
MON, TUE, WED, THU, FRI, SAT, SUN = range(7)


class classproperty(object):

def __init__(self, getter):
self.getter = getter
self.__doc__ = getter.__doc__

def __get__(self, instance, owner):
return self.getter(owner)


class Calendar(object):

FIXED_HOLIDAYS = ()
Expand All @@ -25,6 +35,15 @@ class Calendar(object):
def __init__(self):
self._holidays = {}

@classproperty
def name(cls):
class_name = cls.__name__
if cls.__doc__:
doc = cls.__doc__.split('\n')
doc = map(lambda s: s.strip(), doc)
return next(s for s in doc if s)
return class_name

def get_fixed_holidays(self, year):
"""Return the fixed days according to the FIXED_HOLIDAYS class property
"""
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/austria.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('AT')
class Austria(WesternCalendar, ChristianMixin):
name = 'Austria'
'Austria'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "National Holiday"), # Staatsfeiertag
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/belgium.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('BE')
class Belgium(WesternCalendar, ChristianMixin):
name = 'Belgium'
'Belgium'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/bulgaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('BG')
class Bulgaria(WesternCalendar, ChristianMixin):
name = 'Bulgaria'
'Bulgaria'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(3, 3, "Liberation Day"), # Ден на Освобождението на Б
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/croatia.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('HR')
class Croatia(WesternCalendar, ChristianMixin):
name = 'Croatia'
'Croatia'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "International Workers' Day"),
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/cyprus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@iso_register('CY')
class Cyprus(WesternCalendar, ChristianMixin):
name = 'Cyprus'
'Cyprus'

include_epiphany = True
include_clean_monday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/czech_republic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('CZ')
class CzechRepublic(WesternCalendar, ChristianMixin):
name = 'Czech Republic'
'Czech Republic'

include_easter_monday = True
include_good_friday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/denmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@iso_register('DK')
class Denmark(WesternCalendar, ChristianMixin):
name = 'Denmark'
'Denmark'

include_palm_sunday = True
include_holy_thursday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/estonia.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('EE')
class Estonia(WesternCalendar, ChristianMixin):
name = 'Estonia'
'Estonia'

include_good_friday = True
include_easter_sunday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/finland.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@iso_register('FI')
class Finland(WesternCalendar, ChristianMixin):
name = 'Finland'
'Finland'

include_epiphany = True
include_good_friday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/france.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('FR')
class France(WesternCalendar, ChristianMixin):
name = 'France'
'France'

include_easter_monday = True
include_ascension = True
Expand Down
34 changes: 17 additions & 17 deletions workalendar/europe/germany.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@iso_register('DE')
class Germany(WesternCalendar, ChristianMixin):
name = 'Germany'
'Germany'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
Expand Down Expand Up @@ -42,7 +42,7 @@ def get_variable_days(self, year):

@iso_register('DE-BW')
class BadenWurttemberg(Germany):
name = "Baden-Wuerttemberg"
"Baden-Wuerttemberg"

include_epiphany = True
include_corpus_christi = True
Expand All @@ -51,7 +51,7 @@ class BadenWurttemberg(Germany):

@iso_register('DE-BY')
class Bavaria(Germany):
name = 'Bavaria'
'Bavaria'

include_epiphany = True
include_corpus_christi = True
Expand All @@ -61,65 +61,65 @@ class Bavaria(Germany):

@iso_register('DE-BE')
class Berlin(Germany):
name = 'Berlin'
'Berlin'


@iso_register('DE-BB')
class Brandenburg(Germany):
name = 'Brandenburg'
'Brandenburg'

include_easter_sunday = True
include_reformation_day = True


@iso_register('DE-HB')
class Bremen(Germany):
name = 'Bremen'
'Bremen'


@iso_register('DE-HH')
class Hamburg(Germany):
name = 'Hamburg'
'Hamburg'


@iso_register('DE-HE')
class Hesse(Germany):
name = 'Hesse'
'Hesse'

include_corpus_christi = True


@iso_register('DE-MV')
class MecklenburgVorpommern(Germany):
name = 'Mecklenburg-Western Pomerania'
'Mecklenburg-Western Pomerania'

include_reformation_day = True


@iso_register('DE-NI')
class LowerSaxony(Germany):
name = 'Lower Saxony'
'Lower Saxony'


@iso_register('DE-NW')
class NorthRhineWestphalia(Germany):
name = 'North Rhine-Westphalia'
'North Rhine-Westphalia'

include_corpus_christi = True
include_all_saints = True


@iso_register('DE-RP')
class RhinelandPalatinate(Germany):
name = 'Rhineland-Palatinate'
'Rhineland-Palatinate'

include_corpus_christi = True
include_all_saints = True


@iso_register('DE-SL')
class Saarland(Germany):
name = 'Saarland'
'Saarland'

include_corpus_christi = True
include_assumption = True
Expand All @@ -128,7 +128,7 @@ class Saarland(Germany):

@iso_register('DE-SN')
class Saxony(Germany):
name = 'Saxony'
'Saxony'

include_reformation_day = True

Expand All @@ -147,19 +147,19 @@ def get_variable_days(self, year):

@iso_register('DE-ST')
class SaxonyAnhalt(Germany):
name = 'Saxony-Anhalt'
'Saxony-Anhalt'

include_epiphany = True
include_reformation_day = True


@iso_register('DE-SH')
class SchleswigHolstein(Germany):
name = 'Schleswig-Holstein'
'Schleswig-Holstein'


@iso_register('DE-TH')
class Thuringia(Germany):
name = 'Thuringia'
'Thuringia'

include_reformation_day = True
2 changes: 1 addition & 1 deletion workalendar/europe/greece.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('GR')
class Greece(OrthodoxMixin, WesternCalendar):
name = 'Greece'
'Greece'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(3, 25, "Independence Day"),
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/hungary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('HU')
class Hungary(WesternCalendar, ChristianMixin):
name = 'Hungary'
'Hungary'

include_easter_sunday = True
include_easter_monday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/iceland.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@iso_register('IS')
class Iceland(WesternCalendar, ChristianMixin):
name = 'Iceland'
'Iceland'

include_holy_thursday = True
include_good_friday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/ireland.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@iso_register('IE')
class Ireland(WesternCalendar, ChristianMixin):
name = 'Ireland'
'Ireland'

include_easter_monday = True
include_boxing_day = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/italy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('IT')
class Italy(WesternCalendar, ChristianMixin):
name = 'Italy'
'Italy'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(4, 25, "Liberation Day"),
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/latvia.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@iso_register('LV')
class Latvia(WesternCalendar, ChristianMixin):
name = 'Latvia'
'Latvia'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(5, 1, "Labour Day"),
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/lithuania.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@iso_register('LT')
class Lithuania(WesternCalendar, ChristianMixin):
name = 'Lithuania'
'Lithuania'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(2, 16, "Restoration of the State Day"),
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/luxembourg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('LU')
class Luxembourg(WesternCalendar, ChristianMixin):
name = 'Luxembourg'
'Luxembourg'

include_easter_monday = True
include_ascension = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/malta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('MT')
class Malta(WesternCalendar, ChristianMixin):
name = 'Malta'
'Malta'

include_good_friday = True
include_assumption = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/netherlands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@iso_register('NL')
class Netherlands(WesternCalendar, ChristianMixin):
name = 'Netherlands'
'Netherlands'

include_good_friday = True
include_easter_sunday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/norway.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('NO')
class Norway(WesternCalendar, ChristianMixin):
name = 'Norway'
'Norway'

include_holy_thursday = True
include_good_friday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/poland.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('PL')
class Poland(WesternCalendar, ChristianMixin):
name = 'Poland'
'Poland'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(1, 6, 'Trzech Kroli'),
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/portugal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@iso_register('PT')
class Portugal(WesternCalendar, ChristianMixin):
name = 'Portugal'
'Portugal'

include_good_friday = True
include_easter_sunday = True
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/romania.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@iso_register('RO')
class Romania(WesternCalendar, OrthodoxMixin):
name = 'Romania'
'Romania'

FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + (
(1, 2, "Day After New Years"),
Expand Down
2 changes: 1 addition & 1 deletion workalendar/europe/russia.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@iso_register('RU')
class Russia(WesternCalendar):
name = 'Russia'
'Russia'

shift_new_years_day = True

Expand Down
Loading

0 comments on commit 8472fbb

Please sign in to comment.