[issue10073] calendar.isleap() not checking parameter type

Boštjan Mejak report at bugs.python.org
Sun Oct 17 21:54:25 CEST 2010


Boštjan Mejak <bostjan.mejak at gmail.com> added the comment:

Let me fix this function a little bit...

def isleap(year):
    """Return True for leap years, False for non-leap years."""
    if year == 0:
        raise ValueError('year 0 does not exist')
    return (year % 4 == 0) and (year % 100 != 0) or (year % 400 == 0)

This function, however, does not mind if you give it a negative number. But I think we can leave this option to mean B.C. (Before Christ), so calendar.isleap(-240) would mean 240 B.C., which was a leap year.

About the  if year == 0  check... Well, read Wikipedia's article  http://en.wikipedia.org/wiki/0_(year)  which clearly states that "Year zero does not exist in the widely used Gregorian calendar or in its predecessor, the Julian calendar."  So we raise a ValueError if this value is used in the calendar.isleap() function.

I have uploaded a patch that fixes this function. Please apply it to the trunk and also to the maintenance brances.

----------
keywords: +patch
Added file: http://bugs.python.org/file19255/calendar-isleap.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10073>
_______________________________________


More information about the Python-bugs-list mailing list