[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

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

[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

[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 ___

[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 ___

[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,

[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

[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

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

[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),

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

[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: $