[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Eric V. Smith


Eric V. Smith  added the comment:

I think I'd just do 3.9 and master. It does seem subtle for a minor release, 
when people are less likely to be looking at the release notes.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Mark Dickinson


Mark Dickinson  added the comment:

I'm wondering how far back the fix should be backported. Clearly it should go 
into the 3.9 branch as well as master, but it feels like the sort of fix where 
the behaviour change resulting from the fix is as likely to break code as the 
bug itself.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Mark Dickinson


Mark Dickinson  added the comment:

The PR is ready for review.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Mark Dickinson


Mark Dickinson  added the comment:

Created a PR with a tentative fix. It still needs regression tests; working on 
those.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Mark Dickinson


Change by Mark Dickinson :


--
keywords: +patch
pull_requests: +19692
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/20435

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Eric V. Smith


Eric V. Smith  added the comment:

For completeness, here's the output using just format, which I prefer over 
str.format because there's less going on: it removes all of the str.format 
machinery and basically directly calls obj.__format__.

>>> format(1504, '.3g')
'1.5e+03'
>>> format(1505, '.3g')
'1.50e+03'
>>> format(1506, '.3g')
'1.51e+03'

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Mark Dickinson


Mark Dickinson  added the comment:

This appears to go all the way down to _Py_dg_dtoa, which in mode 3 is supposed 
to suppress trailing zeros.

I'll dig in and see if I can find a fix. (Assigning to me so that I don't 
forget it, but I also don't want to block anyone else - if anyone else feels 
like working on this, please do go ahead.)

--
assignee:  -> mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Mark Dickinson


Mark Dickinson  added the comment:

Very interesting. Agreed that this looks like a bug. It affects old-style 
formatting, too:

>>> "%.3g" % 1503
'1.5e+03'
>>> "%.3g" % 1504
'1.5e+03'
>>> "%.3g" % 1505
'1.50e+03'

--
versions: +Python 3.10, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Eric V. Smith


Change by Eric V. Smith :


--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Eric V. Smith


Eric V. Smith  added the comment:

FWIW, which is probably not much with ".g" formatting, this is how Decimal 
behaves:

>>> from decimal import Decimal as D
>>> format(D(1504), '.3g')
'1.50e+3'
>>> format(D(1505), '.3g')
'1.50e+3'
>>> format(D(1506), '.3g')
'1.51e+3'
>>> format(D(1504.0), '.3g')
'1.50e+3'
>>> format(D(1505.0), '.3g')
'1.50e+3'
>>> format(D(1506.0), '.3g')
'1.51e+3'
>>> format(D("1504.0"), '.3g')
'1.50e+3'
>>> format(D("1505.0"), '.3g')
'1.50e+3'
>>> format(D("1506.0"), '.3g')
'1.51e+3'

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread Eric V. Smith


Change by Eric V. Smith :


--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40780] str.format() handles trailing zeros inconsistently in “general” format

2020-05-26 Thread David Chambers

New submission from David Chambers :

According to 
https://docs.python.org/3/library/string.html#format-specification-mini-language,
 “insignificant trailing zeros are removed from the significand” when 'g' is 
specified. I encountered a situation in which a trailing zero is not removed:

$ python3
Python 3.7.7 (default, Mar 10 2020, 15:43:03)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> '{0:.3g}'.format(1504)
'1.5e+03'
>>> '{0:.3g}'.format(1505)
'1.50e+03'
>>> '{0:.3g}'.format(1506)
'1.51e+03'

Is this behaviour intentional? If so, why is the trailing zero in 1.50 
considered significant for 1505 but insignificant for 1504?

--
messages: 369983
nosy: davidchambers
priority: normal
severity: normal
status: open
title: str.format() handles trailing zeros inconsistently in “general” format
type: behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com