[Tutor] question about calendar module in standard libriary

Steven D'Aprano steve at pearwood.info
Mon Sep 11 10:42:36 EDT 2017


On Mon, Sep 11, 2017 at 10:58:51AM +0000, Айнур Зулькарнаев wrote:

> class Calendar(object):
>     def __init__(self, firstweekday=0):
>         self.firstweekday = firstweekday # 0 = Monday, 6 = Sunday
> 
>     def getfirstweekday(self):
>         return self._firstweekday % 7
> 
>     def setfirstweekday(self, firstweekday):
>         self._firstweekday = firstweekday
> 
>     firstweekday = property(getfirstweekday, setfirstweekday)
>
> As far as I understand, even if user enters inappropriate firstweekday 
> parameter (bigger than 6) during instansiation of the Calendar, the 
> Calendar swallows it (and latter returns correct firstweekday value 
> due to %7 in getfirstweekday method).

That looks right to me.

> So, the question is why not explicitly raise ValueError if user enters 
> the firstweekday parameter bigger that 6 (with accordance with the 
> Zen). Am I missing something?

I don't think there is any specific reason. Probably just the personal 
choice of the person who wrote the code. The decision doesn't appear to 
be documented anywhere, so I don't think its official behaviour.


-- 
Steve


More information about the Tutor mailing list