Skip to content

gh-131146: Fix month names in a genitive case in calendar module #131147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

plashchynski
Copy link

@plashchynski plashchynski commented Mar 12, 2025

The calendar module displays month names in some locales using the genitive case. This is grammatically incorrect, as the nominative case should be used when the month is named by itself. To address this issue, this change introduces new lists alt_month_name and alt_month_abbr that contain month names in the nominative case. The module now uses %OB format specifier to get month names in the nominative case where available.

The calendar module displays month names in some locales using the genitive case.
This is grammatically incorrect, as the nominative case should be used when the month
is named by itself. To address this issue, this change introduces new lists
`alt_month_name` and `alt_month_abbr` that contain month names in the nominative case.
The module now uses `%OB` format specifier to get month names in the nominative case
where available.
@ghost
Copy link

ghost commented Mar 12, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Mar 12, 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.

Copy link
Member

@tomasr8 tomasr8 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! This will also need a NEWS entry and tests (check Lib/test/test_calendar.py)

@plashchynski
Copy link
Author

@picnixz Sorry for that, it was due to a rebase to main. I've fixed it.

* Use assertListEqual to ensure alternate month names the same as regular
for the "C" locale.
* Use `_supports_alternative_month_names` as more descriptive name.
* Add `versionadded:: next` tags to the new APIs.
… and `calendar.alt_month_abbr` to `calendar.standalone_month_abbr`.
* Limit line length to 79 characters according to PEP8
* Suppress current unit links according to the Documentation Style Guide
@hugovk hugovk changed the title gh-131146: Fix month names in a genitive case in calendar module. gh-131146: Fix month names in a genitive case in calendar module Mar 24, 2025
Comment on lines +496 to +498
A sequence that represents the months of the year in the current locale.
This follows normal convention of January being month number 1, so it has
a length of 13 and ``month_name[0]`` is the empty string.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just a formatting change and should not be included in this PR.

Comment on lines +516 to +517
locale. This follows normal convention of January being month number 1, so
it has a length of 13 and ``month_abbr[0]`` is the empty string.
Copy link
Contributor

Choose a reason for hiding this comment

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

Again unrelated formatting changes

Comment on lines +146 to +152
try:
standalone_month_name = _localized_month('%OB')
standalone_month_abbr = _localized_month('%Ob')
except ValueError:
# The platform does not support the %OB and %Ob specifiers.
standalone_month_name = month_name
standalone_month_abbr = month_abbr
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
try:
standalone_month_name = _localized_month('%OB')
standalone_month_abbr = _localized_month('%Ob')
except ValueError:
# The platform does not support the %OB and %Ob specifiers.
standalone_month_name = month_name
standalone_month_abbr = month_abbr
try:
standalone_month_name = _localized_month('%OB')
standalone_month_abbr = _localized_month('%Ob')
except ValueError:
standalone_month_name = month_name
standalone_month_abbr = month_abbr

The previous comment covers this IMO

Comment on lines +1 to +3
Add :data:`calendar.standalone_month_name` and :data:`calendar.standalone_month_abbr` to
provide month names and abbreviations in a grammatical form used when a month name stands
by itself if the locale provides one.
Copy link
Contributor

Choose a reason for hiding this comment

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

Both the NEWS entries are for the same issue, they could just be merged. "Fix ... by adding :data:calendar.standalone_month_name and :data:calendar.standalone_month_abbr. These provide ... "

@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 29, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @encukou for commit 36bb456 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F131147%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 29, 2025
@encukou
Copy link
Member

encukou commented Apr 29, 2025

Thank you for the PR, @plashchynski
If you don't beat me to it, I plan to fix the formatting/comments/entries tomorrow so that this gets into 3.14.

@StanFromIreland
Copy link
Contributor

This also needs a proper test (my comment was incorrectly closed) using support's @run_with_locale, grep the existing tests for usage examples, there are quite a few.


>>> import calendar
>>> list(calendar.month_name)
['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

.. caution::

In locales with alternative forms of month names, the :data:`!month_name` sequence
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
In locales with alternative forms of month names, the :data:`!month_name` sequence
In locales with alternative month names forms, the :data:`!month_name` sequence

Simpler rewording

Comment on lines +537 to +540
>>> import calendar
>>> list(calendar.standalone_month_name)
['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

Copy link
Contributor

@StanFromIreland StanFromIreland Apr 29, 2025

Choose a reason for hiding this comment

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

This example is pointless in the English locale, and it links to month_name with the exact same example.

Comment on lines +551 to +554
>>> import calendar
>>> list(calendar.standalone_month_abbr)
['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

@@ -139,6 +140,17 @@ def __len__(self):
month_name = _localized_month('%B')
month_abbr = _localized_month('%b')

# On platforms that support the %OB and %Ob specifiers, it is used
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# On platforms that support the %OB and %Ob specifiers, it is used
# On platforms that support the %OB and %Ob specifiers, they are used

grammar


A sequence that represents the months of the year in the current locale
in the grammatical form used when a month name stands by itself if the locale
provides one. If the locale does not supply an alternative form, it is equal to
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
provides one. If the locale does not supply an alternative form, it is equal to
provides one. If the locale does not supply a standalone form, it is equal to

Maybe this would be clearer?

Comment on lines +532 to +534
A sequence that represents the months of the year in the current locale
in the grammatical form used when a month name stands by itself if the locale
provides one. If the locale does not supply an alternative form, it is equal to
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
A sequence that represents the months of the year in the current locale
in the grammatical form used when a month name stands by itself if the locale
provides one. If the locale does not supply an alternative form, it is equal to
A sequence that represents the months of the year in the current locale
in the standalone form if the locale provides one. Else it is equivalent to

Much simpler format, as docs should be e.g.

Comment on lines +532 to +534
A sequence that represents the months of the year in the current locale
in the grammatical form used when a month name stands by itself if the locale
provides one. If the locale does not supply an alternative form, it is equal to
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
A sequence that represents the months of the year in the current locale
in the grammatical form used when a month name stands by itself if the locale
provides one. If the locale does not supply an alternative form, it is equal to
A sequence that represents the months of the year in the current locale
in the standalone form if the locale provides one. Else it is equivalent to

Much simpler format, as docs should be e.g.

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.

8 participants