Skip to content

Commit 435be06

Browse files
EoinTrialpicnixzStanFromIreland
authored
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>
1 parent 0469e6d commit 435be06

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

Doc/library/calendar.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,14 @@ The :mod:`!calendar` module defines the following exceptions:
580580

581581
.. exception:: IllegalMonthError(month)
582582

583-
A subclass of :exc:`ValueError`,
583+
A subclass of :exc:`ValueError` and :exc:`IndexError`,
584584
raised when the given month number is outside of the range 1-12 (inclusive).
585585

586+
.. versionchanged:: 3.12
587+
:exc:`IllegalMonthError` is now also a subclass of
588+
:exc:`ValueError`. New code should avoid catching
589+
:exc:`IndexError`.
590+
586591
.. attribute:: month
587592

588593
The invalid month number.

Lib/test/test_calendar.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,17 @@ def test_formatmonth(self):
495495
calendar.TextCalendar().formatmonth(0, 2),
496496
result_0_02_text
497497
)
498+
498499
def test_formatmonth_with_invalid_month(self):
499500
with self.assertRaises(calendar.IllegalMonthError):
500501
calendar.TextCalendar().formatmonth(2017, 13)
501502
with self.assertRaises(calendar.IllegalMonthError):
502503
calendar.TextCalendar().formatmonth(2017, -1)
503504

505+
def test_illegal_month_error_bases(self):
506+
self.assertIsSubclass(calendar.IllegalMonthError, ValueError)
507+
self.assertIsSubclass(calendar.IllegalMonthError, IndexError)
508+
504509
def test_formatmonthname_with_year(self):
505510
self.assertEqual(
506511
calendar.HTMLCalendar().formatmonthname(2004, 1, withyear=True),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Document that :class:`calendar.IllegalMonthError` is a subclass of both
2+
:exc:`ValueError` and :exc:`IndexError` since Python 3.12.

0 commit comments

Comments
 (0)