Skip to content

gh-153158: Remove the erroneous width argument of HTMLCalendar.formatmonthpage - #153159

Open
tonghuaroot wants to merge 3 commits into
python:mainfrom
tonghuaroot:calendar-formatmonthpage-width
Open

gh-153158: Remove the erroneous width argument of HTMLCalendar.formatmonthpage#153159
tonghuaroot wants to merge 3 commits into
python:mainfrom
tonghuaroot:calendar-formatmonthpage-width

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

HTMLCalendar.formatmonthpage was added in 3.15 with a width argument copied from formatyearpage. A single month has no width to lay out, and HTMLCalendar.formatmonth's third positional is withyear, so width was silently forwarded as withyear. A falsy value dropped the year from the month heading:

>>> import calendar
>>> b'June 2009' in calendar.HTMLCalendar().formatmonthpage(2009, 6, 0)
False   # withyear=0, year dropped

This removes the parameter. The default output is unchanged. formatmonthpage is new in 3.15, which has not shipped a final release (latest tag v3.15.0b3), so removing it rather than deprecating it is safe; this should be backported to 3.15 only.

Note: dropping the parameter also means formatmonthpage(y, m, 3) now passes 3 to css rather than the (bogus) width. formatmonthpage is currently undocumented in Doc/library/calendar.rst; adding a doc entry is a separate follow-up.

I have left the backport label for a maintainer to assign.

…formatmonthpage

The argument is a meaningless copy-paste from formatyearpage; a single month has no width. formatmonthpage is new in 3.15 (currently unreleased at 3.15.0b3), so remove it rather than keep a broken argument.
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 16, 2026

@serhiy-storchaka serhiy-storchaka left a comment

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.

LGTM. 👍

cc @hugovk

Comment thread Lib/calendar.py
return self._format_html_page(theyear, content, css, encoding)

def formatmonthpage(self, theyear, themonth, width=3, css='calendar.css', encoding=None):
def formatmonthpage(self, theyear, themonth, css='calendar.css', encoding=None):

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.

To avoid errors it is better to make css and further keyword-only.

I wonder if the method needs the withyear parameter. Anyway it is not documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting merge needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants