Commits

Ezio Melotti  committed 59a2807 Merge

#15421: merge with 3.2.

  • Participants
  • Parent commits b1d6daf, aa73e60

Comments (0)

Files changed (3)

File Lib/calendar.py

         oneday = datetime.timedelta(days=1)
         while True:
             yield date
-            date += oneday
+            try:
+                date += oneday
+            except OverflowError:
+                # Adding one day could fail after datetime.MAXYEAR
+                break
             if date.month != month and date.weekday() == self.firstweekday:
                 break
 

File Lib/test/test_calendar.py

 import time
 import locale
 import sys
+import datetime
 
 result_2004_01_text = """
     January 2004
         new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
         self.assertEqual(old_october, new_october)
 
+    def test_itermonthdates(self):
+        # ensure itermonthdates doesn't overflow after datetime.MAXYEAR
+        # see #15421
+        list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12))
+
 
 class MonthCalendarTestCase(unittest.TestCase):
     def setUp(self):
 Library
 -------
 
+- Issue #15421: fix an OverflowError in Calendar.itermonthdates() after
+  datetime.MAXYEAR.  Patch by Cédric Krier.
+
 - Issue #15970: xml.etree.ElementTree now serializes correctly the empty HTML
   elements 'meta' and 'param'.