[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-19 Thread Michael Amrhein
Michael Amrhein added the comment: Created new issue for tracking the deficiencies in the documentation: https://bugs.python.org/issue39096. -- resolution: -> wont fix stage: -> resolved status: open -> closed ___ Python tracker

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-18 Thread Michael Amrhein
Michael Amrhein added the comment: Mark, Eric, sometimes the pressure to be backwards compatible is more of a curse than a blessing. But I can live with your decision. And, yes, I will create two separate issues regarding the docs. -- ___ Python

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-18 Thread Eric V. Smith
Eric V. Smith added the comment: I agree with your approach, Mark. And Michael: thanks for your report on the C behavior. I just wish we'd thought to look at this 13 years ago when .format() was being discussed. -- ___ Python tracker

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-18 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks, Eric. I'm now convinced that we shouldn't weaken the Decimal behaviour, and I agree that it's risky to change the float and int behaviour. So it's sounding as though we're looking at a "won't fix" resolution here. There are still the documentation

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Eric V. Smith
Eric V. Smith added the comment: I agree that a quick glance in the rear view mirror shows that the design isn't awesome. But I just don't see how we can change it at this point. It is what it is. And it's no surprise that int and float have the same behavior: they share the same code in

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Michael Amrhein
Michael Amrhein added the comment: > > ... Has anyone checked what C does? > #include int main() { int i = -12345; double f = -12345.0; printf("%-020d\n", i); printf("%020d\n", i); printf("%20d\n", i); printf("%-020f\n", f); printf("%020f\n", f);

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Mark Dickinson
Mark Dickinson added the comment: [Eric] > Is that the "0" here: [...] Yes, sorry; that could have been clearer. > In particular, what if you specify a different alignment type with the > pre-width 0? Right, that's the critical question here. For floats and ints, an explicitly-specified

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Eric V. Smith
Eric V. Smith added the comment: I'm not sure what you mean by the "pre-width 0". Is that the "0" here: format_spec ::= [[fill]align][sign][#][0][width][grouping_option][.precision][type] ? And now that I write out the question, I'm sure that's what you mean. PEP 3101 says "If the width

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Mark Dickinson
Mark Dickinson added the comment: > Regarding cases 3-7 I'd like to suggest a slightly different resolution: Hmm, yes. I was concentrating on the Decimal results, but I agree that these int/float results are disturbing: >>> format(12345, "<020") '12345000' >>> format(12345.0,

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Michael Amrhein
Michael Amrhein added the comment: Mark, to answer your question regarding the two implementations of Decimals: No, in the cases I stated above there are no differences in their behaviour. In order to dig a bit deeper, I wrote a little test: d = cdec.Decimal("1234567890.1234") p =

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Michael Amrhein
Michael Amrhein added the comment: Mark, I mostly agree with your classifications / proposals. Regarding cases 3-7 I'd like to suggest a slightly different resolution: Following my interpretation of the spec ("use zeropad *only* if no align is given"), "<020", ">020", "^020" and "=020" would

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks for the report. I think most of this is a documentation issue: we either need to make clear that the formatting documentation applies only to the float type and that Decimal follows its own rules (usually for good reason, namely that it's required to

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Mark Dickinson
Change by Mark Dickinson : -- Removed message: https://bugs.python.org/msg358567 ___ Python tracker ___ ___ Python-bugs-list

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks for the report. I think most of this is a documentation issue: we either need to make clear that the formatting documentation applies only to the float type and that Decimal follows its own rules (usually for good reason, namely that it's required to

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Mark Dickinson
Change by Mark Dickinson : -- nosy: +mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Eric V. Smith
Change by Eric V. Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39077] Numeric formatting inconsistent between int, float and Decimal

2019-12-17 Thread Michael Amrhein
New submission from Michael Amrhein : The __format__ methods of int, float and Decimal (C and Python implementation) do not interpret the Format Specification Mini-Language in the same way: >>> import decimal as cdec ... cdec.__file__ ... '/usr/lib64/python3.6/decimal.py' >>> import