FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-46659: calendar uses locale.getlocale() by vstinner · Pull Request #31166 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (3) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Doc/library/calendar.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
.. note::

The :meth:`formatweekday` and :meth:`formatmonthname` methods of these two
classes temporarily change the current locale to the given *locale*. Because
classes temporarily change the ``LC_TIME`` locale to the given *locale*. Because
the current locale is a process-wide setting, they are not thread-safe.


Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.11.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ Changes in the Python API
of sorting simply isn't well-defined in the absence of a total ordering
on list elements.

* :mod:`calendar`: The :class:`calendar.LocaleTextCalendar` and
:class:`calendar.LocaleHTMLCalendar` classes now use
:func:`locale.getlocale`, instead of using :func:`locale.getdefaultlocale`,
if no locale is specified.
(Contributed by Victor Stinner in :issue:`46659`.)


Build Changes
=============
Expand Down
4 changes: 2 additions & 2 deletions Lib/calendar.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ class LocaleTextCalendar(TextCalendar):
def __init__(self, firstweekday=0, locale=None):
TextCalendar.__init__(self, firstweekday)
if locale is None:
locale = _locale.getdefaultlocale()
locale = _locale.getlocale(_locale.LC_TIME)
self.locale = locale

def formatweekday(self, day, width):
Expand All @@ -586,7 +586,7 @@ class LocaleHTMLCalendar(HTMLCalendar):
def __init__(self, firstweekday=0, locale=None):
HTMLCalendar.__init__(self, firstweekday)
if locale is None:
locale = _locale.getdefaultlocale()
locale = _locale.getlocale(_locale.LC_TIME)
self.locale = locale

def formatweekday(self, day):
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_calendar.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,8 @@ def test_option_locale(self):
self.assertFailure('-L')
self.assertFailure('--locale')
self.assertFailure('-L', 'en')
lang, enc = locale.getdefaultlocale()

lang, enc = locale.getlocale()
lang = lang or 'C'
enc = enc or 'UTF-8'
try:
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The :class:`calendar.LocaleTextCalendar` and
:class:`calendar.LocaleHTMLCalendar` classes now use :func:`locale.getlocale`,
instead of using :func:`locale.getdefaultlocale`, if no locale is specified.
Patch by Victor Stinner.

Back | FazBrowse Home | New Git URL