Айнур Зулькарнаев wrote:

> Hello all!
> 
> 
> There is a class Calendar in calendar.py in standard libriary.
> 
> 
> class Calendar(object):
>         """
>         Base calendar class. This class doesn't do any formatting. It
>         simply provides data to subclasses.
>         """
> 
>         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).
> 
> 
> 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?

It does no harm to those who use the class properly while it allows those 
unfamiliar with the idea of a 0th day to specify 7 instead 0. The behaviour 
thus may be interpreted as an example of

"""Be strict when sending and tolerant when receiving."""

See also

https://tools.ietf.org/html/rfc1958
https://en.wikipedia.org/wiki/Robustness_principle

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to