Skip to content

Commit 9badac0

Browse files
committed
Rename calendar.alt_month_name to calendar.standalone_month_name, and calendar.alt_month_abbr to calendar.standalone_month_abbr.
1 parent 46c7513 commit 9badac0

File tree

4 files changed

+43
-31
lines changed

4 files changed

+43
-31
lines changed

Doc/library/calendar.rst

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -493,51 +493,63 @@ The :mod:`calendar` module exports the following data attributes:
493493

494494
.. data:: month_name
495495

496-
A sequence that represents the months of the year in the current locale
497-
in the grammatical form used when the month is part of a complete date.
496+
A sequence that represents the months of the year in the current locale.
498497
This follows normal convention of January being month number 1, so it has
499498
a length of 13 and ``month_name[0]`` is the empty string.
500499

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

504+
.. caution::
505+
506+
In locales with alternative forms of month names, the :data:`month_name` sequence
507+
may not be suitable when a month name stands by itself and not as part of a date.
508+
For instance, in Greek and in many Slavic and Baltic languages, :data:`month_name`
509+
will produce the month in genitive case. Use :data:`standalone_month_name` for a form
510+
suitable for standalone use.
511+
505512

506513
.. data:: month_abbr
507514

508515
A sequence that represents the abbreviated months of the year in the current
509-
locale in the grammatical form used when the month is part of a complete date.
510-
This follows normal convention of January being month number 1, so it has
511-
a length of 13 and ``month_abbr[0]`` is the empty string.
516+
locale. This follows normal convention of January being month number 1, so
517+
it has a length of 13 and ``month_abbr[0]`` is the empty string.
512518

513519
>>> import calendar
514520
>>> list(calendar.month_abbr)
515521
['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
516522

523+
.. caution::
524+
525+
In locales with alternative forms of month names, the :data:`month_abbr` sequence
526+
may not be suitable when a month name stands by itself and not as part of a date.
527+
Use :data:`standalone_month_abbr` for a form suitable for standalone use.
528+
517529

518-
.. data:: alt_month_name
530+
.. data:: standalone_month_name
519531

520532
A sequence that represents the months of the year in the current locale
521-
in the grammatical form used when the month is named by itself if the locale
522-
provides one. If the locale does not supply an alternative form, it falls back
523-
to the behavior of :data:`month_name`.
533+
in the grammatical form used when a month name stands by itself if the locale
534+
provides one. If the locale does not supply an alternative form, it is equal to
535+
:data:`month_name`.
524536

525537
>>> import calendar
526-
>>> list(calendar.alt_month_name)
538+
>>> list(calendar.standalone_month_name)
527539
['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
528540

529541
.. versionadded:: next
530542

531543

532-
.. data:: alt_month_abbr
544+
.. data:: standalone_month_abbr
533545

534546
A sequence that represents the abbreviated months of the year in the current
535-
locale in the grammatical form used when the month is named by itself if the
536-
locale provides one. If the locale does not supply an alternative form, it falls
537-
back to the behavior of :data:`month_abbr`.
547+
locale in the grammatical form used when a month name stands by itself if the
548+
locale provides one. If the locale does not supply an alternative form, it is equal to
549+
:data:`month_abbr`.
538550

539551
>>> import calendar
540-
>>> list(calendar.alt_month_abbr)
552+
>>> list(calendar.standalone_month_abbr)
541553
['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
542554

543555
.. versionadded:: next

Lib/calendar.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
1515
"firstweekday", "isleap", "leapdays", "weekday", "monthrange",
1616
"monthcalendar", "prmonth", "month", "prcal", "calendar",
17-
"timegm", "month_name", "month_abbr", "alt_month_name",
18-
"alt_month_abbr", "day_name", "day_abbr", "Calendar",
17+
"timegm", "month_name", "month_abbr", "standalone_month_name",
18+
"standalone_month_abbr", "day_name", "day_abbr", "Calendar",
1919
"TextCalendar", "HTMLCalendar", "LocaleTextCalendar",
2020
"LocaleHTMLCalendar", "weekheader",
2121
"Day", "Month", "JANUARY", "FEBRUARY", "MARCH",
@@ -144,12 +144,12 @@ def __len__(self):
144144
# standalone form of the month name. This is required for some languages
145145
# such as Greek, Slavic, and Baltic languages.
146146
try:
147-
alt_month_name = _localized_month('%OB')
148-
alt_month_abbr = _localized_month('%Ob')
147+
standalone_month_name = _localized_month('%OB')
148+
standalone_month_abbr = _localized_month('%Ob')
149149
except ValueError:
150150
# The platform does not support the %OB and %Ob specifiers.
151-
alt_month_name = month_name
152-
alt_month_abbr = month_abbr
151+
standalone_month_name = month_name
152+
standalone_month_abbr = month_abbr
153153

154154

155155
def isleap(year):
@@ -389,7 +389,7 @@ def formatmonthname(self, theyear, themonth, width, withyear=True):
389389
"""
390390
_validate_month(themonth)
391391

392-
s = alt_month_name[themonth]
392+
s = standalone_month_name[themonth]
393393
if withyear:
394394
s = "%s %r" % (s, theyear)
395395
return s.center(width)
@@ -522,9 +522,9 @@ def formatmonthname(self, theyear, themonth, withyear=True):
522522
"""
523523
_validate_month(themonth)
524524
if withyear:
525-
s = '%s %s' % (alt_month_name[themonth], theyear)
525+
s = '%s %s' % (standalone_month_name[themonth], theyear)
526526
else:
527-
s = alt_month_name[themonth]
527+
s = standalone_month_name[themonth]
528528
return '<tr><th colspan="7" class="%s">%s</th></tr>' % (
529529
self.cssclass_month_head, s)
530530

Lib/test/test_calendar.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ def test_days(self):
546546
self.assertEqual(value[::-1], list(reversed(value)))
547547

548548
def test_months(self):
549-
for attr in ("month_name", "month_abbr", "alt_month_name",
550-
"alt_month_abbr"):
549+
for attr in ("month_name", "month_abbr", "standalone_month_name",
550+
"standalone_month_abbr"):
551551
value = getattr(calendar, attr)
552552
self.assertEqual(len(value), 13)
553553
self.assertEqual(len(value[:]), 13)
@@ -557,12 +557,12 @@ def test_months(self):
557557
# verify it "acts like a sequence" in two forms of iteration
558558
self.assertEqual(value[::-1], list(reversed(value)))
559559

560-
def test_alt_month_name_and_abbr(self):
561-
# Ensure that the alternate month names and abbreviations are equal
560+
def test_standalone_month_name_and_abbr(self):
561+
# Ensure that the standalone 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.assertListEqual(list(calendar.month_name), list(calendar.alt_month_name))
565-
self.assertListEqual(list(calendar.month_abbr), list(calendar.alt_month_abbr))
564+
self.assertListEqual(list(calendar.month_name), list(calendar.standalone_month_name))
565+
self.assertListEqual(list(calendar.month_abbr), list(calendar.standalone_month_abbr))
566566

567567
def test_locale_text_calendar(self):
568568
try:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Add :func:`calendar.alt_month_name` and :func:`calendar.alt_month_abbr` to
1+
Add :func:`calendar.standalone_month_name` and :func:`calendar.standalone_month_abbr` to
22
provide alternative month names and abbreviations for the current locale
33
when available. These are used when the month is named by itself, such as in
44
a standalone date.

0 commit comments

Comments
 (0)