Skip to content

Conversation

@plusminushalf
Copy link
Contributor

>>> import locale; >>> print(locale.format('%.0f KB', 100)) 100 KB >>> locale.format.__doc__ 'Deprecated, use format_string instead.'
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow these steps to rectify the issue:

  1. Sign the PSF contributor agreement
  2. Wait at least one US business day and then check "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  3. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

@bitdancer
Copy link
Member

Thanks for working on this. Doc changes are also needed.

@bitdancer
Copy link
Member

As well as tests for the deprecation message.

@bitdancer
Copy link
Member

Somehow I hadn't noticed that 'monetary' wasn't supported by format_string. So that is actually an enhancement, in addition to the deprecation, and needs to be documented as such (versionchanged, whats new entry). Also, format itself shouldn't be changed, just deprecated (that is, the deprecation message code added, but nothing else in it changed).

@plusminushalf
Copy link
Contributor Author

@bitdancer I don't think to keep locale.format as it is and just displaying deprecated warning would be of any use. I think it is safe to call locale.format_string internally.

grouping strings.
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"

@bitdancer
Copy link
Member

That's the way we normally do deprecations: leave the existing code in place (so its behavior doesn't change) but point people to the preferred solution. It would be acceptable if there were no behavior changes, but the changed tests prove that there are.

Copy link
Member

@bitdancer bitdancer left a comment

Choose a reason for hiding this comment

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

Thanks. Almost there :)

It would also be good to have an entry for the What's New document for 3.7 for the addition of the monetary parameter to format_string, as well as the deprecation of format. I haven't looked; if the 3.7 what's new hasn't been organized yet, just stick in a placeholder sentence with a reference to the bpo issue number.

.. versionchanged:: 3.7
Added *monetary*, if true the conversion uses monetary thousands separator and
grouping strings.
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.

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:
Copy link
Member

Choose a reason for hiding this comment

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

You can use assertWarns here instead.


.. versionchanged:: 3.7
The *monetary* keyword parameter was added.
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.

I don't think the 'replaces' sentence is needed. The deprecated on format covers that.

Copy link
Member

@bitdancer bitdancer left a comment

Choose a reason for hiding this comment

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

Thanks for sticking with this :)

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.

Missing indentation.

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.

@codecov
Copy link

codecov bot commented Feb 27, 2017

Codecov Report

Merging #259 into master will decrease coverage by -1.01%.
The diff coverage is 71.42%.

@@ Coverage Diff @@ ## master #259 +/- ## ========================================== - Coverage 83.38% 82.38% -1.01%  ========================================== Files 1367 1428 +61 Lines 344897 351221 +6324 ========================================== + Hits 287596 289342 +1746  - Misses 57301 61879 +4578

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae160bb...6097e47. Read the comment docs.

Improved Modules
================

* Added another argument *monetary* in :meth:`format_string` of :mod:`locale`.
Copy link
Member

Choose a reason for hiding this comment

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

There should be a subsection header before this line for the locale module (the modules with enhancements are listed in this section in alphabetical order).

@plusminushalf
Copy link
Contributor Author

@bitdancer is it good to go now?

@bitdancer
Copy link
Member

Yes, I think so. I'd like to do a final overall review before I approve it, though. With any luck I'll do that tonight.

@plusminushalf
Copy link
Contributor Author

Thanks! :)

@plusminushalf
Copy link
Contributor Author

Hey, @bitdancer have you reviewed this?

@bitdancer
Copy link
Member

I did...and I feel bad that I have some more changes to suggest, so I was going to make them myself and submit it to the PR, but I haven't actually figured out how to do that yet.

@plusminushalf
Copy link
Contributor Author

@bitdancer well I think you can suggest me the changes I'll do my best to figure them out.

For whole format strings, use :func:`format_string`.

.. deprecated:: 3.7
Use :meth:`format_string` instead
Copy link
Member

Choose a reason for hiding this comment

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

So looking at this again, I think what we should do is move 'format' under 'format_string', and change its body to say "works like format_string but only accepts a single format specification. That followed by the deprecation notice will make it a lot less likely anyone will use it :)

If *monetary* is true, the conversion uses monetary thousands separator and
grouping strings.
(Contributed by Garvit in :issue:`10379`.)

Copy link
Member

Choose a reason for hiding this comment

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

Small nit: our convention appears to be to put the Contributed by as part of the paragraph when there's only one paragraph. Ends up formatted the same in html, but might as well make the ReST consistent as well.

Lib/locale.py Outdated
"""Deprecated, use format_string instead."""
warnings.warn(
"This method will be removed in future versions. "
"Use 'locale.format_string()' instead.",
Copy link
Member

Choose a reason for hiding this comment

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

I think this should read "This method will be removed in a future version of Python."

"""Formats a string in the same way that the % formatting would use,
but takes the current locale into account.
Grouping is applied if the third parameter is true."""
Grouping is applied if the third parameter is true.
Copy link
Member

Choose a reason for hiding this comment

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

As long as we are editing this, I think there should be a blank line after the first sentence, before the 'Grouping' sentence.

Lib/locale.py Outdated
"the 'C' locale.")

s = format('%%.%if' % digits, abs(val), grouping, monetary=True)
s = format_string('%%.%if' % digits, abs(val), grouping, monetary=True)
Copy link
Member

Choose a reason for hiding this comment

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

Since we know there's only one format string here, I think this should be a call to _format.

Lib/locale.py Outdated
def str(val):
"""Convert float to string, taking the locale into account."""
return format("%.12g", val)
return format_string("%.12g", val)
Copy link
Member

Choose a reason for hiding this comment

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

As above, I think this should be _format.

Refactoring Doc, moving format doc below format_string, this is to make sure people have lesser probability of using format in future. Also using _format method inside locale module, since we know there is only one format function that is _format
@bitdancer
Copy link
Member

There was no need to move format in the source file, but it doesn't hurt, either.

@plusminushalf
Copy link
Contributor Author

Hey @bitdancer is there anything left to get this merged?

@bitdancer
Copy link
Member

Just adding the Misc/NEWS entry. I'm not sure what status is on how to do that currently, but I think it is still manual edit of that file. I haven't had time yet to learn how to update a PR before merge, so if you add the entry, I'll hit merge :)

Misc/NEWS Outdated
- bpo-29534: Fixed different behaviour of Decimal.from_float()
for _decimal and _pydecimal. Thanks Andrew Nester.

- bpo-10379: Deprecate locale.format in lue of locale.format_string
Copy link
Member

Choose a reason for hiding this comment

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

Google says it's spelled 'lieu'. Also the entry should note that the monetary argument was added to format_string. So, how about "locale.format_string now supports the 'monetary' keyword argument, and locale.format is deprecated."

@plusminushalf plusminushalf changed the title bpo-10379: deprecate locale.format in lue of locale.format_string bpo-10379: deprecate locale.format in lieu of locale.format_string Mar 28, 2017
@bitdancer bitdancer merged commit 1cf93a7 into python:master Mar 28, 2017
akruis added a commit to akruis/cpython that referenced this pull request Aug 8, 2021
Update the Stackless patches for readthedocs.org based on the documentation. This simplified configuration is still untested.
akruis added a commit to akruis/cpython that referenced this pull request Aug 8, 2021
Well, the previous commit didn't build on readthedocs.org. - Rename .readthedocs.yml to .readthedocs.yaml See https://docs.readthedocs.io/en/stable/config-file/index.html - Add a requirements file Doc/slp_readthedocs_requirements.txt and require the same packages as specified in Makefile. Already set the Sphinx version to 2.0.1, because upstream commit 7d23dbe
akruis added a commit to akruis/cpython that referenced this pull request Aug 8, 2021
Set the css-file to "pydoctheme.css".
akruis added a commit to akruis/cpython that referenced this pull request Aug 8, 2021
Remove the explicit specification of the css-file for readthedocs.org. It is not needed any more.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants