-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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
base: main
Are you sure you want to change the base?
gh-131146: Fix month names in a genitive case in calendar module #131147
Conversation
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.
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 |
There was a problem hiding this 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
)
@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
Misc/NEWS.d/next/Library/2025-03-17-21-15-04.gh-issue-131146.P9Cdx0.rst
Outdated
Show resolved
Hide resolved
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. |
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again unrelated formatting changes
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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. |
There was a problem hiding this comment.
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 ... "
🤖 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. |
Thank you for the PR, @plashchynski |
This also needs a proper test (my comment was incorrectly closed) using |
|
||
>>> 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
>>> import calendar | ||
>>> list(calendar.standalone_month_name) | ||
['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | ||
|
There was a problem hiding this comment.
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.
>>> import calendar | ||
>>> list(calendar.standalone_month_abbr) | ||
['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] | ||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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
andalt_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.