https://github.com/python/cpython/commit/639df39bf0b7e1172ebc4df84c1ae097ea7c0c22
commit: 639df39bf0b7e1172ebc4df84c1ae097ea7c0c22
branch: main
author: Petr Viktorin <encu...@gmail.com>
committer: encukou <encu...@gmail.com>
date: 2025-08-13T07:03:05Z
summary:

gh-131146: Fall back to `month_name` if `standalone_month_name`s aren't 
distinct (GH-137674)

Some systems reportedly don't expand '%OB' and '%Ob'.
In this case (and similar theoretically possible ones, like expanding to empty
string or 'OB'), fall back to the month_name & month_abbr.

files:
M Lib/calendar.py

diff --git a/Lib/calendar.py b/Lib/calendar.py
index 45bb265a65602c..fd6c561a9d39b8 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -149,6 +149,14 @@ def __len__(self):
 except ValueError:
     standalone_month_name = month_name
     standalone_month_abbr = month_abbr
+else:
+    # Some systems that do not support '%OB' will keep it as-is (i.e.,
+    # we get [..., '%OB', '%OB', '%OB']), so for non-distinct names,
+    # we fall back to month_name/month_abbr.
+    if len(set(standalone_month_name)) != len(set(month_name)):
+        standalone_month_name = month_name
+    if len(set(standalone_month_abbr)) != len(set(month_abbr)):
+        standalone_month_abbr = month_abbr
 
 
 def isleap(year):

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to