Message331042
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. |
|
Date |
User |
Action |
Args |
2018-12-04 13:14:45 | asocia | set | recipients:
+ asocia, rhettinger, belopolsky, serhiy.storchaka |
2018-12-04 13:14:45 | asocia | set | messageid: <1543929285.41.0.788709270274.issue35406@psf.upfronthosting.co.za> |
2018-12-04 13:14:45 | asocia | link | issue35406 messages |
2018-12-04 13:14:45 | asocia | create | |
|