diff -r c6892ce7e56f Lib/calendar.py --- a/Lib/calendar.py Mon Sep 17 09:01:03 2012 +0200 +++ b/Lib/calendar.py Fri Sep 21 00:13:56 2012 +0200 @@ -161,7 +161,11 @@ oneday = datetime.timedelta(days=1) while True: yield date - date += oneday + try: + date += oneday + except OverflowError: + # Adding one day could result a date out of range + break if date.month != month and date.weekday() == self.firstweekday: break diff -r c6892ce7e56f Lib/test/test_calendar.py --- a/Lib/test/test_calendar.py Mon Sep 17 09:01:03 2012 +0200 +++ b/Lib/test/test_calendar.py Fri Sep 21 00:13:56 2012 +0200 @@ -6,6 +6,7 @@ import time import locale import sys +import datetime result_2004_01_text = """ January 2004 @@ -464,6 +465,10 @@ new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEqual(old_october, new_october) + def test_itermonthdates(self): + # ensure itermonthdates works for all months + list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12)) + class MonthCalendarTestCase(unittest.TestCase): def setUp(self):