GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-10379: deprecate locale.format in lieu of locale.format_string by plusminushalf · Pull Request #259 · python/cpython

Conversation

@plusminushalf

@plusminushalf plusminushalf commented Feb 23, 2017

Copy link
Copy Markdown
Contributor
>>> import locale;
>>> print(locale.format('%.0f KB', 100))
100 KB
>>> locale.format.__doc__
'Deprecated, use format_string instead.'

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@plusminushalf
bpo-10379: deprecate locale.format in lue of locale.format_string
d0f9863
@the-knights-who-say-ni

the-knights-who-say-ni commented Feb 23, 2017

Copy link
Copy Markdown

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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Feb 23, 2017
@bitdancer

bitdancer commented Feb 23, 2017

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bitdancer

bitdancer commented Feb 23, 2017

Copy link
Copy Markdown
Member

As well as tests for the deprecation message.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Mariatta Mariatta removed the CLA not signed label Feb 24, 2017
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Feb 24, 2017
@plusminushalf
Adding tests and documentation changes
820e289
@bitdancer

bitdancer commented Feb 24, 2017

Copy link
Copy Markdown
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).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@plusminushalf
Adding version changed info for locale.format
4cfd737
@plusminushalf

plusminushalf commented Feb 24, 2017

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bitdancer
bitdancer requested changes Feb 24, 2017
View reviewed changes
Comment thread Doc/library/locale.rst
grouping strings.
Replaces :meth:`format`.


@bitdancer bitdancer Feb 24, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bitdancer

bitdancer commented Feb 24, 2017

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@plusminushalf
Deprecating but not changing the function defination
a08419f
bitdancer
bitdancer requested changes Feb 24, 2017
View reviewed changes

@bitdancer bitdancer left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/locale.rst Outdated
.. versionchanged:: 3.7
Added *monetary*, if true the conversion uses monetary thousands separator and
grouping strings.
The *monetary* keyword parameter was added.

@bitdancer bitdancer Feb 24, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_locale.py Outdated
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:

@bitdancer bitdancer Feb 24, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/locale.rst Outdated

.. versionchanged:: 3.7
The *monetary* keyword parameter was added.
Replaces :meth:`format`.

@bitdancer bitdancer Feb 24, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@plusminushalf
Adding documentation inside what's new in 3.7
4e24a3f
Fixed recommended CR changes
@plusminushalf
plusminushalf force-pushed the fix-bpo-10379 branch from 052f6bc to 4e24a3f Compare February 25, 2017 15:07
bitdancer
bitdancer requested changes Feb 26, 2017
View reviewed changes

@bitdancer bitdancer left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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 :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/locale.rst Outdated
locale settings into account.

.. versionchanged:: 3.7
The *monetary* keyword parameter was added.

@bitdancer bitdancer Feb 26, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Missing indentation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/whatsnew/3.7.rst Outdated
function instead.

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

@bitdancer bitdancer Feb 26, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@plusminushalf
Adding whatsnew documentation in proper segments
6097e47
@codecov

codecov Bot commented Feb 27, 2017

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

plusminushalf added 2 commits February 27, 2017 19:30
@plusminushalf
Merge branch 'master' of github.com:python/cpython into fix-bpo-10379
04577c2
@plusminushalf
fixing documentation bug
2039406
bitdancer
bitdancer requested changes Feb 27, 2017
View reviewed changes
Comment thread Doc/whatsnew/3.7.rst Outdated
Improved Modules
================

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

@bitdancer bitdancer Feb 27, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@plusminushalf
Adding locale subsection
5b100b8
@plusminushalf

plusminushalf commented Mar 3, 2017

Copy link
Copy Markdown
Contributor Author

@bitdancer is it good to go now?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bitdancer

bitdancer commented Mar 3, 2017

Copy link
Copy Markdown
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 reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@plusminushalf

plusminushalf commented Mar 3, 2017

Copy link
Copy Markdown
Contributor Author

Thanks! :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@plusminushalf
Merge branch 'master' of github.com:python/cpython into fix-bpo-10379
041349f
@plusminushalf

plusminushalf commented Mar 17, 2017

Copy link
Copy Markdown
Contributor Author

Hey, @bitdancer have you reviewed this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bitdancer

bitdancer commented Mar 17, 2017

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@plusminushalf

plusminushalf commented Mar 17, 2017

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bitdancer
bitdancer reviewed Mar 17, 2017
View reviewed changes
Comment thread Doc/library/locale.rst Outdated
For whole format strings, use :func:`format_string`.

.. deprecated:: 3.7
Use :meth:`format_string` instead

@bitdancer bitdancer Mar 17, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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 :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/whatsnew/3.7.rst
If *monetary* is true, the conversion uses monetary thousands separator and
grouping strings.
(Contributed by Garvit in :issue:`10379`.)

@bitdancer bitdancer Mar 17, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/locale.py Outdated
"""Deprecated, use format_string instead."""
warnings.warn(
"This method will be removed in future versions. "
"Use 'locale.format_string()' instead.",

@bitdancer bitdancer Mar 17, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/locale.py
"""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.

@bitdancer bitdancer Mar 17, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 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)

@bitdancer bitdancer Mar 17, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 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)

@bitdancer bitdancer Mar 17, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@plusminushalf
Refactoring Doc, using _format inisde locale module
795aa65
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

bitdancer commented Mar 20, 2017

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bitdancer
bitdancer approved these changes Mar 20, 2017
View reviewed changes
@plusminushalf

plusminushalf commented Mar 27, 2017

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bitdancer

bitdancer commented Mar 27, 2017

Copy link
Copy Markdown
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 :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@plusminushalf
Adding entry to Misc/NEWS about changes
8190fa9
bitdancer
bitdancer requested changes Mar 28, 2017
View reviewed changes
Comment thread 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

@bitdancer bitdancer Mar 28, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@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
@plusminushalf
CR fixes
7e0bfcf
bitdancer
bitdancer approved these changes Mar 28, 2017
View reviewed changes
@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
@akruis
Stackless issue python#259: Update Doc/conf.py and .readthedocs.yml
b87f882
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
@akruis
Stackless issue python#259: Update Doc/conf.py and .readthedocs.yml
a15ae9c
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
@akruis
Stackless issue python#259: Update Doc/conf.py
53ca885
Set the css-file to "pydoctheme.css".
akruis added a commit to akruis/cpython that referenced this pull request Aug 8, 2021
@akruis
Stackless issue python#259: Update Doc/conf.py
e61be11
Remove the explicit specification of the css-file for readthedocs.org.
It is not needed any more.
@roe-dl roe-dl mentioned this pull request Oct 27, 2024
AttributeError: module 'locale' has no attribute 'format'. Did you mean: '_format'? (Python 3.12) poblabs/weewx-belchertown#954
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bitdancer bitdancer bitdancer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@plusminushalf @the-knights-who-say-ni @bitdancer @Mariatta
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.