FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-148663: Document that `calendar.IllegalMonthError` inherits from both `ValueError` and `IndexError` (GH-148664) by miss-islington · Pull Request #148917 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 6 additions & 1 deletion Doc/library/calendar.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_calendar.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL