Skip to content

gh-148663: Document that IllegalMonthError inherits from both ValueError and IndexError#148664

Open
EoinTrial wants to merge 2 commits intopython:mainfrom
EoinTrial:fix/calendar-illegalmontherror-docs
Open

gh-148663: Document that IllegalMonthError inherits from both ValueError and IndexError#148664
EoinTrial wants to merge 2 commits intopython:mainfrom
EoinTrial:fix/calendar-illegalmontherror-docs

Conversation

@EoinTrial
Copy link
Copy Markdown

@EoinTrial EoinTrial commented Apr 17, 2026

The documentation for calendar.IllegalMonthError describes it only as "a subclass of ValueError", but the source code defines it as:

class IllegalMonthError(ValueError, IndexError):

The IndexError base class is intentional for backwards compatibility (see the source comment in Lib/calendar.py), but this is not mentioned in the docs. Users catching IndexError for bad month numbers won't know their code still works after Python 3.13.


📚 Documentation preview 📚: https://cpython-previews--148664.org.readthedocs.build/

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Apr 17, 2026

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 19, 2026

  1. Can you add a versionchanged directive indicating that this is now inheriting ValuerError and IndexError since 3.13 (I did not check when it was changed so pick the correct version).
  2. Reword the NEWS entry
  3. Add a test to ensure that we do not remove that double inheritance.

@EoinTrial EoinTrial force-pushed the fix/calendar-illegalmontherror-docs branch from 58e98ba to 1781682 Compare April 19, 2026 14:32
@EoinTrial EoinTrial requested a review from AA-Turner as a code owner April 19, 2026 14:32
@EoinTrial
Copy link
Copy Markdown
Author

@picnixz Thanks for taking a look! I've added the versionchanged:: 3.12 directive, rewritten the NEWS entry, and added test_illegal_month_error_bases to verify the dual inheritance.

Comment thread Doc/library/calendar.rst Outdated
Comment thread Doc/library/calendar.rst Outdated
Comment thread Doc/library/calendar.rst Outdated
Python 3.13.

.. versionchanged:: 3.12
:exc:`IllegalMonthError` is now also a subclass of :exc:`IndexError`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:exc:`IllegalMonthError` is now also a subclass of :exc:`IndexError`.
:exc:`IllegalMonthError`is now also a subclass of :exc:`ValueError`. Newer code should avoid catching :exc:`IndexError`.

And make that paragraph fit on 80 chars.

Comment thread Lib/test/test_calendar.py Outdated
calendar.TextCalendar().formatmonth(2017, -1)

def test_illegal_month_error_bases(self):
self.assertTrue(issubclass(calendar.IllegalMonthError, ValueError))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a helper assertIsSubclass

@EoinTrial EoinTrial force-pushed the fix/calendar-illegalmontherror-docs branch from 1781682 to c4e2753 Compare April 19, 2026 16:46
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@EoinTrial EoinTrial requested a review from picnixz April 19, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants