Skip to content

Conversation

@pgdr
Copy link
Contributor

@pgdr pgdr commented Oct 16, 2025

Running python3.13 -m calendar 2025 pretty-prints the calendar for all of 2025. If we add the month at the end, it only prints the month.

python3.13 -m calendar 2025

It is possible to get HTML output by using python -m calendar -t html 2025, which gives the calender for 2025 in HTML format.

However, if we add the month, python -m calendar -t html 2025 10 it fails:

[~]$ python3.13 -m calendar -t html 2025 10
usage: calendar.py [-h] [-w WIDTH] [-l LINES] [-s SPACING] [-m MONTHS] [-c CSS] [-L LOCALE] [-e ENCODING] [-t {text,html}] [-f FIRST_WEEKDAY]
                   [year] [month]
calendar.py: error: incorrect number of arguments

This PR simply adds support for HTML-formatting the year-month option.

A test is included, and one existing test is removed: a test verifying that the year month option fails.

@pgdr pgdr requested a review from AA-Turner as a code owner October 16, 2025 19:05
@python-cla-bot
Copy link

python-cla-bot bot commented Oct 16, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Oct 16, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@pgdr
Copy link
Contributor Author

pgdr commented Oct 16, 2025

Note that the html produced in Calendar.formatmonthpage is essentially copied verbatim from Calender.formatyearpage. There is potential for code reuse and extracting common (html) code into a new function.

I didn't do this at this stage because it would actually be a larger change, and I'm not sure this will be merged regardless.

Let me know if I should extract the common code out.

Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a blurb and docs.

@pgdr
Copy link
Contributor Author

pgdr commented Oct 16, 2025

@StanFromIreland I have added a blurb and updated documentation for Calendar's argparser.

I was not sure if the blurb was supposed to go in Core_and_Builtins or elsewhere, I will move it to its correct location if it's wrong.

I have updated the docs as well.

I think it's best to squash the commits before a hypothetical merging. I'll do so upon request.

@StanFromIreland
Copy link
Member

StanFromIreland commented Oct 16, 2025

It should be in Library.

Squash is done by the commiter, please don't force push, it only causes confusion.

@pgdr
Copy link
Contributor Author

pgdr commented Oct 20, 2025

@StanFromIreland I have moved the blurb to Library.

@pgdr pgdr changed the title gh-140212: Add html for year-date option in Calendar gh-140212: Add html for year-month option in Calendar Oct 22, 2025
pgdr and others added 2 commits October 22, 2025 11:48
Contributed by hugovk

Co-authored-by: Hugo van Kemenade <[email protected]>
@hugovk
Copy link
Member

hugovk commented Oct 23, 2025

Please could you also list this in What's New?

https://docs.python.org/3.15/whatsnew/3.15.html#calendar

@pgdr
Copy link
Contributor Author

pgdr commented Oct 23, 2025

@hugovk It's done (given that the entry is acceptable).

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@pgdr
Copy link
Contributor Author

pgdr commented Oct 27, 2025

@AA-Turner Let me know if there is anything I can do at this point to get this PR merged.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants