[3.15] gh-153158: Remove the erroneous width argument of HTMLCalendar.formatmonthpage (GH-153159) (#155932)

hugovk <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/b4aae1d2a2f2f4aa4e16a191e8bf6050c46ce0d1
commit: b4aae1d2a2f2f4aa4e16a191e8bf6050c46ce0d1
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2026-08-17T06:15:29Z
summary:

[3.15] gh-153158: Remove the erroneous width argument of HTMLCalendar.formatmonthpage (GH-153159) (#155932)

Co-authored-by: tonghuaroot (童话) <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-07-06-10-30-00.gh-issue-153158.m0nthP.rst
M Lib/calendar.py
M Lib/test/test_calendar.py

diff --git a/Lib/calendar.py b/Lib/calendar.py
index 92fe6b7723fe268..7aaaf73bfe0044b 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 8646cfcad58cea8..04eb5155a82118f 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..3850860fb2f8db1
--- /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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.