Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 064e393

Browse files
committed
Issue #3067: Enhance the documentation and docstring of locale.setlocale()
2 parents 8c481b6 + 395ca72 commit 064e393

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

Doc/library/locale.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ The :mod:`locale` module defines the following exception and functions:
2222

2323
.. exception:: Error
2424

25-
Exception raised when :func:`setlocale` fails.
25+
Exception raised when the locale passed to :func:`setlocale` is not
26+
recognized.
2627

2728

2829
.. function:: setlocale(category, locale=None)
2930

30-
If *locale* is specified, it may be a string, a tuple of the form ``(language
31-
code, encoding)``, or ``None``. If it is a tuple, it is converted to a string
32-
using the locale aliasing engine. If *locale* is given and not ``None``,
33-
:func:`setlocale` modifies the locale setting for the *category*. The available
34-
categories are listed in the data description below. The value is the name of a
35-
locale. An empty string specifies the user's default settings. If the
36-
modification of the locale fails, the exception :exc:`Error` is raised. If
37-
successful, the new locale setting is returned.
31+
If *locale* is given and not ``None``, :func:`setlocale` modifies the locale
32+
setting for the *category*. The available categories are listed in the data
33+
description below. *locale* may be a string, or an iterable of two strings
34+
(language code and encoding). If it's an iterable, it's converted to a locale
35+
name using the locale aliasing engine. An empty string specifies the user's
36+
default settings. If the modification of the locale fails, the exception
37+
:exc:`Error` is raised. If successful, the new locale setting is returned.
3838

3939
If *locale* is omitted or ``None``, the current setting for *category* is
4040
returned.

Lib/locale.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,10 @@ def getlocale(category=LC_CTYPE):
526526
def setlocale(category, locale=None):
527527

528528
""" Set the locale for the given category. The locale can be
529-
a string, a locale tuple (language code, encoding), or None.
529+
a string, an iterable of two strings (language code and encoding),
530+
or None.
530531
531-
Locale tuples are converted to strings the locale aliasing
532+
Iterables are converted to strings using the locale aliasing
532533
engine. Locale strings are passed directly to the C lib.
533534
534535
category may be given as one of the LC_* values.

Misc/NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ Library
358358
are read correctly.
359359

360360
- Issue #3067: locale.setlocale() now raises TypeError if the second
361-
argument is an invalid iterable. Initial patch by Jyrki Pulliainen.
361+
argument is an invalid iterable. Its documentation and docstring
362+
were also updated. Initial patch by Jyrki Pulliainen.
362363

363364
- Issue #13140: Fix the daemon_threads attribute of ThreadingMixIn.
364365

0 commit comments

Comments
 (0)