Skip to content

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

Merged
hugovk merged 4 commits into
python:mainfrom
tonghuaroot:calendar-formatmonthpage-width
Aug 17, 2026
Merged

hugovk merged 4 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 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 Outdated
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.

They are error-prone positionally, which is how the width bug arose. The method is undocumented; formatyearpage is documented, so leave it.
@tonghuaroot

Copy link
Copy Markdown
Contributor Author

Done in 1df0894: made formatmonthpage's css/encoding keyword-only. Left formatyearpage as-is since it's documented with the positional signature (that one's better as a separate change with a versionchanged note).

@hugovk hugovk 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.

Thanks!

@hugovk
hugovk merged commit 1ad63cc into python:main Aug 17, 2026
51 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @tonghuaroot for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Aug 17, 2026

Copy link
Copy Markdown

GH-155932 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Aug 17, 2026
hugovk pushed a commit that referenced this pull request Aug 17, 2026
….formatmonthpage (GH-153159) (#155932)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants