https://github.com/python/cpython/commit/2459faaaa9300723c376989e08ba8335d2f480a1
commit: 2459faaaa9300723c376989e08ba8335d2f480a1
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-04-27T21:00:46+01:00
summary:

[3.14] gh-148663: Document that `calendar.IllegalMonthError` inherits from both 
`ValueError` and `IndexError` (GH-148664) (#148917)

(cherry picked from commit 435be06dd25a5e4e19014340c4ba873d71051c4c)

Co-authored-by: Eoin Shaughnessy <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>

files:
A Misc/NEWS.d/next/Documentation/2026-04-17-02-28-55.gh-issue-148663.MHIbRB.rst
M Doc/library/calendar.rst
M Lib/test/test_calendar.py

diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst
index 1a4323134b2ee9..e308e5bfb00906 100644
--- a/Doc/library/calendar.rst
+++ b/Doc/library/calendar.rst
@@ -544,9 +544,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.
diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py
index 7ade4271b7a156..ca93e99d1427dc 100644
--- a/Lib/test/test_calendar.py
+++ b/Lib/test/test_calendar.py
@@ -457,12 +457,17 @@ def test_formatmonth(self):
             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),
diff --git 
a/Misc/NEWS.d/next/Documentation/2026-04-17-02-28-55.gh-issue-148663.MHIbRB.rst 
b/Misc/NEWS.d/next/Documentation/2026-04-17-02-28-55.gh-issue-148663.MHIbRB.rst
new file mode 100644
index 00000000000000..0fbe5a699ef0ad
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Documentation/2026-04-17-02-28-55.gh-issue-148663.MHIbRB.rst
@@ -0,0 +1,2 @@
+Document that :class:`calendar.IllegalMonthError` is a subclass of both
+:exc:`ValueError` and :exc:`IndexError` since Python 3.12.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to