This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients belopolsky, jiangping.li, rhettinger, serhiy.storchaka, xiang.zhang
Date 2016-09-26.18:34:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474914866.68.0.420091445594.issue28253@psf.upfronthosting.co.za>
In-reply-to
Content
> 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].
History
Date User Action Args
2016-09-26 18:34:26belopolskysetrecipients: + belopolsky, rhettinger, serhiy.storchaka, xiang.zhang, jiangping.li
2016-09-26 18:34:26belopolskysetmessageid: <1474914866.68.0.420091445594.issue28253@psf.upfronthosting.co.za>
2016-09-26 18:34:26belopolskylinkissue28253 messages
2016-09-26 18:34:26belopolskycreate