[Python-checkins] cpython (merge 3.2 -> default): #15421: merge with 3.2.

ezio.melotti python-checkins at python.org
Fri Sep 21 16:29:44 CEST 2012


http://hg.python.org/cpython/rev/59a2807872d5
changeset:   79090:59a2807872d5
parent:      79087:b1d6daface10
parent:      79089:aa73e60f65e9
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Fri Sep 21 17:29:20 2012 +0300
summary:
   #15421: merge with 3.2.

files:
  Lib/calendar.py           |  6 +++++-
  Lib/test/test_calendar.py |  6 ++++++
  Misc/NEWS                 |  3 +++
  3 files changed, 14 insertions(+), 1 deletions(-)


diff --git a/Lib/calendar.py b/Lib/calendar.py
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -161,7 +161,11 @@
         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
 
diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py
--- a/Lib/test/test_calendar.py
+++ b/Lib/test/test_calendar.py
@@ -6,6 +6,7 @@
 import time
 import locale
 import sys
+import datetime
 
 result_2004_01_text = """
     January 2004
@@ -464,6 +465,11 @@
         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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,9 @@
 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'.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list