From eeca56a57f469c12ed563e8b991478e98270d9b2 Mon Sep 17 00:00:00 2001 From: tonghuaroot Date: Mon, 6 Jul 2026 11:31:46 +0800 Subject: [PATCH 1/2] gh-153158: Remove the erroneous width argument of HTMLCalendar.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. --- Lib/calendar.py | 4 ++-- Lib/test/test_calendar.py | 6 ++++++ .../Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst diff --git a/Lib/calendar.py b/Lib/calendar.py index 92fe6b7723fe268..5eb04cbe7014676 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -609,11 +609,11 @@ def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None): content = self.formatyear(theyear, width) 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): """ Return a formatted month as a complete HTML page. """ - content = self.formatmonth(theyear, themonth, width) + content = self.formatmonth(theyear, themonth) return self._format_html_page(theyear, content, css, encoding) diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index 6ed27b4095bc1db..422ada039fc12c5 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -545,6 +545,12 @@ def test_format_html_year_with_month(self): result_2009_6_html ) + def test_formatmonthpage_no_width(self): + # gh-140212: formatmonthpage must not accept a 'width' argument. + cal = calendar.HTMLCalendar() + self.assertIn(b'class="month">June 2009', cal.formatmonthpage(2009, 6)) + self.assertRaises(TypeError, cal.formatmonthpage, 2009, 6, width=3) + class CalendarTestCase(unittest.TestCase): diff --git a/Misc/NEWS.d/next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst b/Misc/NEWS.d/next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst new file mode 100644 index 000000000000000..9c6f907122b005b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst @@ -0,0 +1,3 @@ +Remove the erroneous *width* argument of +:meth:`calendar.HTMLCalendar.formatmonthpage`, which could drop the year from +the heading. From 726d6c3cf4f049a594cfb2662adc25e36d6fe705 Mon Sep 17 00:00:00 2001 From: tonghuaroot Date: Mon, 6 Jul 2026 12:58:20 +0800 Subject: [PATCH 2/2] Suppress the changelog cross-reference to the undocumented method --- .../next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst b/Misc/NEWS.d/next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst index 9c6f907122b005b..3850860fb2f8db1 100644 --- a/Misc/NEWS.d/next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst +++ b/Misc/NEWS.d/next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst @@ -1,3 +1,3 @@ Remove the erroneous *width* argument of -:meth:`calendar.HTMLCalendar.formatmonthpage`, which could drop the year from +:meth:`!calendar.HTMLCalendar.formatmonthpage`, which could drop the year from the heading.