Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-148663: Document that IllegalMonthError inherits from both ValueEr…
…ror and IndexError
  • Loading branch information
EoinTrial committed Apr 19, 2026
commit c4e275362fb19f978fccfae447181dd9cbc176df
10 changes: 9 additions & 1 deletion Doc/library/calendar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,16 @@ The :mod:`!calendar` module defines the following exceptions:

.. exception:: IllegalMonthError(month)

A subclass of :exc:`ValueError`,
A subclass of both :exc:`ValueError` and :exc:`IndexError`,
Comment thread
EoinTrial marked this conversation as resolved.
Outdated
raised when the given month number is outside of the range 1-12 (inclusive).
The :exc:`IndexError` base class is preserved for backwards compatibility
with code that caught :exc:`IndexError` for bad month numbers prior to
Python 3.13.
Comment thread
EoinTrial marked this conversation as resolved.
Outdated

.. versionchanged:: 3.12
:exc:`IllegalMonthError` is now also a subclass of
:exc:`ValueError`. Newer code should avoid catching
Comment thread
EoinTrial marked this conversation as resolved.
Outdated
:exc:`IndexError`.

.. attribute:: month

Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,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),
Expand Down
Comment thread
StanFromIreland marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Document that :class:`calendar.IllegalMonthError` is a subclass of both
:exc:`ValueError` and :exc:`IndexError` since Python 3.12.
Loading