]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-148663: Document that `calendar.IllegalMonthError` inherits from both ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 27 Apr 2026 20:00:46 +0000 (22:00 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Apr 2026 20:00:46 +0000 (21:00 +0100)
(cherry picked from commit 435be06dd25a5e4e19014340c4ba873d71051c4c)

Co-authored-by: Eoin Shaughnessy <45000144+EoinTrial@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
Doc/library/calendar.rst
Lib/test/test_calendar.py
Misc/NEWS.d/next/Documentation/2026-04-17-02-28-55.gh-issue-148663.MHIbRB.rst [new file with mode: 0644]

index 1a4323134b2ee99bf7563e375f052a5640e3d413..e308e5bfb009061499e35c25f152f7c3fe944075 100644 (file)
@@ -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.
index 7ade4271b7a1564f8b963020cb07db63fa224e77..ca93e99d1427dcb0abce7d8ca6e8905a3505d464 100644 (file)
@@ -457,12 +457,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),
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 (file)
index 0000000..0fbe5a6
--- /dev/null
@@ -0,0 +1,2 @@
+Document that :class:`calendar.IllegalMonthError` is a subclass of both
+:exc:`ValueError` and :exc:`IndexError` since Python 3.12.