You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
calendar displays month names in a genitive case for some locales #131146
A calendar module CLI displays month names in a Polish, and other Slavic languages using the genitive case, as it is used in a phrase "in January". However, for standalone usage, month names should appear in the nominative case to be grammatically correct. For instance, in Polish, "January" should be written as "styczeń" instead of "stycznia"; similarly, in Russian, it should be "январь" rather than "января". This issue likely affects Baltic languages and Greek as well.
Example command demonstrating the issue:
python3 -m calendar --locale pl_PL --encoding utf
This problem occurs because the calendar module uses the strftime %B format specifier, which returns month names suitable for complete date contexts (genitive case). Instead, a nominative form is required when months are mentioned independently:
This problem occurs because the calendar module uses the strftime %B format specifier, which returns month names suitable for complete date contexts (genitive case). Instead, a nominative form is required when months are mentioned independently:
@picnixz to address this issue, I suggest using the %OB format specifier, which returns month names in the nominative case. This specifier is part of the C2x standard and is already supported by most major platforms. Specifically, it has been available in glibc since version 2.27, macOS since 15.3, and Windows as well (tested on Windows 11).
For platforms that do not support %OB, we can continue using %B as a fallback. This way, the module will work correctly on all platforms, but will provide better results on platforms that support %OB. As calendar.month_name is used in other places in the standard library, I suggest adding a new lists alt_month_name and alt_month_abbr to not interfere with the existing behavior.
Ideally, I would want to avoid having a discrepency between platforms (for instance, parsing could be affected) =/ CPython only requires C11 so we can't really assume C2x. However, if this is implemented by major compilers and platforms, maybe we can make an exception? Otherwise, we'll need to wait until C2x is supported officially.
Also, while it is a bug per se, I think we should treat it as a feature instead so to avoid breaking stable Python releases (namely make it only Python 3.14+)
@picnixz thank you for your comments. Just wanted to add that this only affects calendars displayed by TextCalendar and HTMLCalendar when the affected locale is specified, so side effects are minimal.
Also, for locales, discrepancies across platforms are somewhat inevitable. One locale might have alternative ways of writing. A language might have multiple names for a month. For instance, in Belarusian, "May" has two alternative names "май" and "травень". So, it is generally not safe to assume that month names will be strictly consistent across platforms.
Hi! Atfer this change, test_months and test_standalone_month_name_and_abbr_C_locale started failing on Solaris. The reason is that the %0b specifier doesn't exist there and the standalone_month_abbr array becomes just a bunch of '%Ob's because of that.
I see that you added except ValueError: likely to catch issues like this, but I don't think that strftime ever raises a ValueError in that case? (I wasn't able to force it on MacOS with nonexistent specifiers.)
Activity
picnixz commentedon Mar 12, 2025
What would be the format specifier in this case?
pythongh-131146: Fix month names in a genitive case in calendar module.
plashchynski commentedon Mar 12, 2025
@picnixz to address this issue, I suggest using the
%OBformat specifier, which returns month names in the nominative case. This specifier is part of the C2x standard and is already supported by most major platforms. Specifically, it has been available in glibc since version 2.27, macOS since 15.3, and Windows as well (tested on Windows 11).For platforms that do not support
%OB, we can continue using%Bas a fallback. This way, the module will work correctly on all platforms, but will provide better results on platforms that support%OB. Ascalendar.month_nameis used in other places in the standard library, I suggest adding a new listsalt_month_nameandalt_month_abbrto not interfere with the existing behavior.picnixz commentedon Mar 12, 2025
Ideally, I would want to avoid having a discrepency between platforms (for instance, parsing could be affected) =/ CPython only requires C11 so we can't really assume C2x. However, if this is implemented by major compilers and platforms, maybe we can make an exception? Otherwise, we'll need to wait until C2x is supported officially.
cc @hugovk as the RM
picnixz commentedon Mar 12, 2025
Also, while it is a bug per se, I think we should treat it as a feature instead so to avoid breaking stable Python releases (namely make it only Python 3.14+)
plashchynski commentedon Mar 12, 2025
@picnixz thank you for your comments. Just wanted to add that this only affects calendars displayed by
TextCalendarandHTMLCalendarwhen the affected locale is specified, so side effects are minimal.Also, for locales, discrepancies across platforms are somewhat inevitable. One locale might have alternative ways of writing. A language might have multiple names for a month. For instance, in Belarusian, "May" has two alternative names "май" and "травень". So, it is generally not safe to assume that month names will be strictly consistent across platforms.
picnixz commentedon Mar 12, 2025
Oh, I see. So I don't need to bother about the discrepency as we already have possible ones.
gh-131146: Fix month names in a "standalone form" in calendar module (G…
kulikjak commentedon Aug 4, 2025
Hi! Atfer this change,
test_monthsandtest_standalone_month_name_and_abbr_C_localestarted failing on Solaris. The reason is that the%0bspecifier doesn't exist there and thestandalone_month_abbrarray becomes just a bunch of'%Ob's because of that.I see that you added
except ValueError:likely to catch issues like this, but I don't think thatstrftimeever raises aValueErrorin that case? (I wasn't able to force it on MacOS with nonexistent specifiers.)Full failure:
pythongh-131146: Fall back to `month_name` if `standalone_month_name`…
gh-131146: Fall back to `month_name` if `standalone_month_name`s aren…
pythongh-131146: Fix month names in a "standalone form" in calendar m…
pythongh-131146: Fall back to `month_name` if `standalone_month_name`…