gh-148663: Document that calendar.IllegalMonthError inherits from both ValueError and IndexError (#148664)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
This commit is contained in:
Eoin Shaughnessy
2026-04-23 15:50:23 +01:00
committed by GitHub
parent 0469e6d38d
commit 435be06dd2
3 changed files with 13 additions and 1 deletions
+6 -1
View File
@@ -580,9 +580,14 @@ The :mod:`!calendar` module defines the following exceptions:
.. exception:: IllegalMonthError(month)
A subclass of :exc:`ValueError`,
A subclass of :exc:`ValueError` and :exc:`IndexError`,
raised when the given month number is outside of the range 1-12 (inclusive).
.. versionchanged:: 3.12
:exc:`IllegalMonthError` is now also a subclass of
:exc:`ValueError`. New code should avoid catching
:exc:`IndexError`.
.. attribute:: month
The invalid month number.
+5
View File
@@ -495,12 +495,17 @@ class OutputTestCase(unittest.TestCase):
calendar.TextCalendar().formatmonth(0, 2),
result_0_02_text
)
def test_formatmonth_with_invalid_month(self):
with self.assertRaises(calendar.IllegalMonthError):
calendar.TextCalendar().formatmonth(2017, 13)
with self.assertRaises(calendar.IllegalMonthError):
calendar.TextCalendar().formatmonth(2017, -1)
def test_illegal_month_error_bases(self):
self.assertIsSubclass(calendar.IllegalMonthError, ValueError)
self.assertIsSubclass(calendar.IllegalMonthError, IndexError)
def test_formatmonthname_with_year(self):
self.assertEqual(
calendar.HTMLCalendar().formatmonthname(2004, 1, withyear=True),
@@ -0,0 +1,2 @@
Document that :class:`calendar.IllegalMonthError` is a subclass of both
:exc:`ValueError` and :exc:`IndexError` since Python 3.12.