format specification mini-language docs...
Ok, now I'm implementing __format__ support for IronPython. The format spec mini-language docs say that a presentation type of None is the same as 'g' for floating point / decimal values. But these two formats seem to differ based upon how they handle whole numbers:
2.0.__format__('') '2.0' 2.0.__format__('g') '2'
The docs also say that 'g' prints it as fixed point unless the number is too large. But the fixed point format differs from what 'f' would print. I guess it didn't say they'd both print it as fixed point w/ a precision of 6 or anything but it seems a little unclear.
2.0.__format__('g') '2' 2.0.__format__('f') '2.000000'
Finally providing any sign character seems to cause +1.0#INF and friends to be returned instead of inf as is documented:
10e667.__format__('+') '+1.0#INF' 10e667.__format__('') 'inf'
Are these just doc bugs? The inf issue is the only one that seems particularly weird to me.
Dino Viehland wrote:
Ok, now I'm implementing __format__ support for IronPython. The format spec mini-language docs say that a presentation type of None is the same as 'g' for floating point / decimal values.
Awesome! Thanks for doing this.
But these two formats seem to differ based upon how they handle whole numbers:
2.0.__format__('') '2.0' 2.0.__format__('g') '2'
I think the docs are wrong. For floats, the PEP (http://www.python.org/dev/peps/pep-3101/) says: '' (None) - similar to 'g', except that it prints at least one digit after the decimal point.
The docs also say that 'g' prints it as fixed point unless the number is too large. But the fixed point format differs from what 'f' would print. I guess it didn't say they'd both print it as fixed point w/ a precision of 6 or anything but it seems a little unclear.
2.0.__format__('g') '2' 2.0.__format__('f') '2.000000'
This is to be compatible with %-formatting: $ ./python Python 2.7a0 (trunk:67325, Nov 21 2008, 20:35:33) [GCC 4.1.2 20070626 (Red Hat 4.1.2-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
'%f %g' % (2.0, 2.0) '2.000000 2'
Finally providing any sign character seems to cause +1.0#INF and friends to be returned instead of inf as is documented:
10e667.__format__('+') '+1.0#INF' 10e667.__format__('') 'inf'
Yes, that does seem odd. Let me look at it a bit and I'll comment on it, hopefully this weekend. I have a pending fix for 2.7/3.1 to make inf handling more consistent across platforms, it might take care of this case, too.
Are these just doc bugs? The inf issue is the only one that seems particularly weird to me.
Agreed. Eric.
Dino Viehland wrote: <previously discussed cases deleted>
Finally providing any sign character seems to cause +1.0#INF and friends to be returned instead of inf as is documented:
10e667.__format__('+') '+1.0#INF' 10e667.__format__('') 'inf'
Are these just doc bugs? The inf issue is the only one that seems particularly weird to me.
I think the inf one is a bug. Would you mind opening a bug and assigning it to me? Thanks. Eric.
Yep, after the thanksgiving delay I've opened bug #4482 (http://bugs.python.org/issue4482). I either don't know how to or don't have the power to change who a bug is assigned to so it appears to be currently unassigned. -----Original Message----- From: Eric Smith [mailto:eric@trueblade.com] Sent: Tuesday, November 25, 2008 4:38 AM To: Dino Viehland Cc: python-dev@python.org dev Subject: Re: [Python-Dev] format specification mini-language docs... Dino Viehland wrote: <previously discussed cases deleted>
Finally providing any sign character seems to cause +1.0#INF and friends to be returned instead of inf as is documented:
10e667.__format__('+') '+1.0#INF' 10e667.__format__('') 'inf'
Are these just doc bugs? The inf issue is the only one that seems particularly weird to me.
I think the inf one is a bug. Would you mind opening a bug and assigning it to me? Thanks. Eric.
Dino Viehland wrote:
Yep, after the thanksgiving delay I've opened bug #4482 (http://bugs.python.org/issue4482).
Thanks!
I either don't know how to or don't have the power to change who a bug is assigned to so it appears to be currently unassigned.
I'll take care of it. Eric.
-----Original Message----- From: Eric Smith [mailto:eric@trueblade.com] Sent: Tuesday, November 25, 2008 4:38 AM To: Dino Viehland Cc: python-dev@python.org dev Subject: Re: [Python-Dev] format specification mini-language docs...
Dino Viehland wrote:
<previously discussed cases deleted>
Finally providing any sign character seems to cause +1.0#INF and friends to be returned instead of inf as is documented:
10e667.__format__('+') '+1.0#INF' 10e667.__format__('') 'inf'
Are these just doc bugs? The inf issue is the only one that seems particularly weird to me.
I think the inf one is a bug. Would you mind opening a bug and assigning it to me? Thanks.
Eric.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/eric%2Bpython-dev%40truebl...
participants (2)
-
Dino Viehland
-
Eric Smith