Skip to content

calendar.HTMLCalendar.formatmonthpage has a bogus width argument #153158

Description

@tonghuaroot

HTMLCalendar.formatmonthpage, added in 3.15, takes a width argument:

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

The signature was copied from formatyearpage, but a single month has no width to lay out. HTMLCalendar.formatmonth(theyear, themonth, withyear=True) takes withyear as its third positional, so width is forwarded as withyear. A falsy value silently drops the year from the month heading:

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

The argument is meaningless and should be removed. formatmonthpage is new in 3.15, which has not shipped a final release yet (latest tag v3.15.0b3), so removing the parameter rather than deprecating it is safe.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions