Alexander Belopolsky added the comment:
> itermonthdates() is documented public method
The current documentation is an impossibility:
"The iterator will yield datetime.date values and will always iterate through
complete weeks, so it will yield dates outside the specified
month."
The current implementation deals with this impossibility differently for months
(9999, 12) and (1, 1). In the first case, the iterators stops on an out of
bounds date:
>>> list(calendar.Calendar().itermonthdates(9999, 12))[-1]
datetime.date(9999, 12, 31)
>>> list(calendar.Calendar().itermonthdates(9999, 12))[-1].weekday()
4
but in the second, it raises the OverflowError:
>>> next(calendar.Calendar(1).itermonthdates(1, 1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "calendar.py", line 160, in itermonthdates
date -= datetime.timedelta(days=days)
OverflowError: date value out of range
Returning dummy instances instead of datetime.date in these cases will only
make debugging harder for the users of .itermonthdates(). Sooner or later they
would want to do something the returned value that the dummy won't support. If
you are willing to sacrifice the "will yield datetime.date values" for "will
always iterate through complete weeks", I would make it yield None for out of
bounds values and require the caller to deal with this possibility right away.
A better solution would be to simply raise OverflowError whenever the range of
itermonthdates() does not fit within [date.min, date.max].
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue28253>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com