Şahin <akkaya...@itu.edu.tr> added the comment: I'm suggesting this idea to consistency. Why an IllegalMonthError exists in calendar module if we don't raise this error when required?
What would you say if I asked you to "What is the month number coming after 156th month?" Would you say 157 or prefer to inform me that I'm doing something wrong? >>> import calendar >>> calendar.nextmonth(2018, 12) (2019, 1) If Python is smart enough to jump next year's first month and not say (2018, 13) blindly, it should also check if the given month is valid. But: >>> calendar.nextmonth(2018, 157) (2018, 158) I think this is clearly a bug in the code. --------------------------------------------------- I'll wander away from the this issue but some of the functions in calendar module also not consistent with each other: >>> calendar.monthcalendar(2018, 12) # Runs with no problem. >>> calendar.monthcalendar(2018, 0) # Raises IllegalMonthError. >>> calendar.monthcalendar(2018, 13) # Raises IllegalMonthError. >>> calendar.month(2018, 12) # Runs with no problem. >>> calendar.month(2018, 0) # Raises IllegalMonthError. >>> calendar.month(2018, 13) # Raises IndexError??? Why? Wouldn't it be more reasonable if the last one also had raised IllegalMonthError? >>> calendar.monthrange(2018, 12) # Runs with no problem. >>> calendar.monthrange(2018, 0) # Raises IllegalMonthError. >>> calendar.monthrange(2018, 13) # Raises IllegalMonthError. >>> calendar.prmonth(2018, 12) # Runs with no problem. >>> calendar.prmonth(2018, 0) # Raises IllegalMonthError. >>> calendar.prmonth(2018, 13) # Raises IndexError. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35406> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com