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.

classification
Title: Calendar.itermonthdates OverflowError
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: belopolsky, ced, ezio.melotti, python-dev, rhettinger, skip.montanaro, terry.reedy, vstinner
Priority: normal Keywords: patch

Created on 2012-07-22 14:25 by ced, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
calendar.patch ced, 2012-07-22 14:25 calendar.patch review
calendar.patch ced, 2012-09-20 22:15 calendar.patch review
Messages (7)
msg166137 - (view) Author: Cédric Krier (ced) * Date: 2012-07-22 14:25
itermonthdates fails when working on the last month of 9999
Here is a patch that catch the OverflowError.
msg170820 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2012-09-20 15:56
LGTM
msg170824 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-09-20 17:16
Context: http://issues.roundup-tracker.org/issue2550765
msg170854 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-09-20 21:43
Hi Cédric!

         while True:
             yield date
-            date += oneday
+            try:
+                date += oneday
+            except OverflowError:
+                break

You might add a comment explaining why we may get an OverflowError here.

I don't know the cost of adding a try/except in a loop. But the loop has 31 iterations or less, so it's maybe better to keep the explicit try/except around date += oneday.

+    def test_itermonthdates(self):
+        # ensure itermonthdates works for all months
+        list(calendar.Calendar().itermonthdates(9999, 12))

Please use datetime.MAXYEAR instead of this hardcoded constant.
msg170859 - (view) Author: Cédric Krier (ced) * Date: 2012-09-20 22:15
Fix haypo comments
msg170892 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-09-21 14:29
New changeset bfdf366a779a by Ezio Melotti in branch '2.7':
#15421: fix an OverflowError in Calendar.itermonthdates() after datetime.MAXYEAR.  Patch by Cédric Krier.
http://hg.python.org/cpython/rev/bfdf366a779a

New changeset aa73e60f65e9 by Ezio Melotti in branch '3.2':
#15421: fix an OverflowError in Calendar.itermonthdates() after datetime.MAXYEAR.  Patch by Cédric Krier.
http://hg.python.org/cpython/rev/aa73e60f65e9

New changeset 59a2807872d5 by Ezio Melotti in branch 'default':
#15421: merge with 3.2.
http://hg.python.org/cpython/rev/59a2807872d5
msg170893 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-09-21 14:30
Fixed, thanks for the patch and the report!
History
Date User Action Args
2022-04-11 14:57:33adminsetgithub: 59626
2012-09-21 14:30:56ezio.melottisetstatus: open -> closed
resolution: fixed
messages: + msg170893

stage: patch review -> resolved
2012-09-21 14:29:40python-devsetnosy: + python-dev
messages: + msg170892
2012-09-20 22:15:44cedsetfiles: + calendar.patch

messages: + msg170859
2012-09-20 21:43:10vstinnersetmessages: + msg170854
2012-09-20 17:18:08ezio.melottisetassignee: ezio.melotti
2012-09-20 17:16:05terry.reedysetnosy: + terry.reedy
messages: + msg170824
2012-09-20 16:19:32vstinnersetnosy: + vstinner
2012-09-20 15:56:01skip.montanarosetnosy: + skip.montanaro
messages: + msg170820
2012-07-29 21:59:38ezio.melottisetnosy: + rhettinger, belopolsky, ezio.melotti
stage: patch review
type: enhancement -> behavior

versions: + Python 2.7, Python 3.2, Python 3.3
2012-07-22 14:25:43cedcreate