Skip to content

Commit a11ecfb

Browse files
committed
Refinement changes:
* 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.
1 parent 6177415 commit a11ecfb

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Doc/library/calendar.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ The :mod:`calendar` module exports the following data attributes:
526526
>>> list(calendar.alt_month_name)
527527
['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
528528

529+
.. versionadded:: next
530+
529531

530532
.. data:: alt_month_abbr
531533

@@ -538,6 +540,8 @@ The :mod:`calendar` module exports the following data attributes:
538540
>>> list(calendar.alt_month_abbr)
539541
['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
540542

543+
.. versionadded:: next
544+
541545

542546
.. data:: JANUARY
543547
FEBRUARY

Lib/calendar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def __len__(self):
141141
month_abbr = _localized_month('%b')
142142

143143
# Check if the platform supports %OB and %Ob specifiers
144-
def _is_alt_mon_available():
144+
def _supports_alternative_month_names():
145145
try:
146146
datetime.date(2001, 1, 1).strftime('%OB')
147147
datetime.date(2001, 1, 1).strftime('%Ob')
@@ -152,7 +152,7 @@ def _is_alt_mon_available():
152152
# On platforms that support the %OB and %Ob specifiers, it is used to get the
153153
# standalone form of the month name. This is required for some languages
154154
# such as Greek, Slavic, and Baltic languages.
155-
if _is_alt_mon_available():
155+
if _supports_alternative_month_names():
156156
alt_month_name = _localized_month('%OB')
157157
alt_month_abbr = _localized_month('%Ob')
158158
else:
@@ -532,7 +532,7 @@ def formatmonthname(self, theyear, themonth, withyear=True):
532532
if withyear:
533533
s = '%s %s' % (alt_month_name[themonth], theyear)
534534
else:
535-
s = '%s' % alt_month_name[themonth]
535+
s = alt_month_name[themonth]
536536
return '<tr><th colspan="7" class="%s">%s</th></tr>' % (
537537
self.cssclass_month_head, s)
538538

Lib/test/test_calendar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ def test_alt_month_name_and_abbr(self):
561561
# Ensure that the alternate month names and abbreviations are equal
562562
# to the regular month names and abbreviations for the "C" locale.
563563
with calendar.different_locale("C"):
564-
self.assertEqual(list(calendar.month_name), list(calendar.alt_month_name))
565-
self.assertEqual(list(calendar.month_abbr), list(calendar.alt_month_abbr))
564+
self.assertListEqual(list(calendar.month_name), list(calendar.alt_month_name))
565+
self.assertListEqual(list(calendar.month_abbr), list(calendar.alt_month_abbr))
566566

567567
def test_locale_text_calendar(self):
568568
try:

0 commit comments

Comments
 (0)