Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f82b937

Browse files
committed
#15421: merge with 3.2.
2 parents 050a61f + 85710a4 commit f82b937

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lib/calendar.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ def itermonthdates(self, year, month):
161161
oneday = datetime.timedelta(days=1)
162162
while True:
163163
yield date
164-
date += oneday
164+
try:
165+
date += oneday
166+
except OverflowError:
167+
# Adding one day could fail after datetime.MAXYEAR
168+
break
165169
if date.month != month and date.weekday() == self.firstweekday:
166170
break
167171

Lib/test/test_calendar.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
import locale
88
import sys
9+
import datetime
910

1011
result_2004_01_text = """
1112
January 2004
@@ -464,6 +465,11 @@ def test_locale_calendars(self):
464465
new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
465466
self.assertEqual(old_october, new_october)
466467

468+
def test_itermonthdates(self):
469+
# ensure itermonthdates doesn't overflow after datetime.MAXYEAR
470+
# see #15421
471+
list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12))
472+
467473

468474
class MonthCalendarTestCase(unittest.TestCase):
469475
def setUp(self):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- Issue #15421: fix an OverflowError in Calendar.itermonthdates() after
40+
datetime.MAXYEAR. Patch by Cédric Krier.
41+
3942
- Issue #15970: xml.etree.ElementTree now serializes correctly the empty HTML
4043
elements 'meta' and 'param'.
4144

0 commit comments

Comments
 (0)