8000 bpo-10379: deprecate locale.format in lieu of locale.format_string by plusminushalf · Pull Request #259 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-10379: deprecate locale.format in lieu of locale.format_string #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding documentation inside what's new in 3.7
Fixed recommended CR changes
  • Loading branch information
plusminushalf committed Feb 25, 2017
commit 4e24a3f0843e547c9d208717ef5f95d98ddec770
9 changes: 8 additions & 1 deletion Doc/library/locale.rst
Original file line number Diff line number Diff line change
8000 Expand Up @@ -371,12 +371,19 @@ The :mod:`locale` module defines the following exception and functions:

.. function:: format_string(format, val, grouping=False, monetary=False)

Formats a number *val* according to the current :const:`LC_NUMERIC` setting.
The format follows the conventions of the ``%`` operator. For floating point
values, the decimal point is modified if appropriate. If *grouping* is true,
also takes the grouping into account.

If *monetary* is true, the conversion uses monetary thousands separator and
grouping strings.

Processes formatting specifiers as in ``format % val``, but takes the current
locale settings into account.

.. versionchanged:: 3.7
The *monetary* keyword parameter was added.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need the description of the monetary keyword (presumably copy and pasted from the existing format entry) in the description of the format_string function.

In fact, what we really want to do is copy most of the 'format' description into format_string, since it seems wrong somehow to refer to the docs of a deprecated from from the preferred function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing indentation.

Replaces :meth:`format`.


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of the monetary parameter should be added to the regular docs, and the version changed phrase should just say "the monetary keyword parameter was added"

.. function:: currency(val, symbol=True, grouping=False, international=False)
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ API and Feature Removals
Python 3.1, and has now been removed. Use the :func:`~os.path.splitdrive`
function instead.

* Deprecated :meth:`format` from :mod:`locale`, use the :meth:`format_string`
instead. Added another argument *monetary* in :meth:`format_string` of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format hasn't been removed, so the deprecation should go in the deprecation section. The feature addition of the monetary keyword should go in the 'improved modules' section.

:mod:`locale`.
(Contributed by Garvit in :issue:`10379`.)


Porting to Python 3.7
=====================
Expand Down
5 changes: 1 addition & 4 deletions Lib/test/test_locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,8 @@ def test_padding(self):
self._test_format("%-10.f", 4200, grouping=0, out='4200'.ljust(10))

def test_format_deprecation(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always", DeprecationWarning)
with self.assertWarns(DeprecationWarning):
locale.format("%-10.f", 4200, grouping=True)
for warning in w:
self.assertTrue(warning.category is DeprecationWarning)

def test_complex_formatting(self):
# Spaces in formatting string
Expand Down
0