This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author skrah
Recipients eric.smith, mark.dickinson, skrah
Date 2009-09-07.15:21:05
SpamBayes Score 1.110223e-16
Marked as misclassified No
Message-id <20090907172035.GA3983@mail.bytereef.org>
In-reply-to <1252330936.43.0.253303390161.issue6850@psf.upfronthosting.co.za>
Content
Eric Smith <report@bugs.python.org> wrote:
> The test as written will always give an error for None. I think the
> better fix is to change it to be:
> 
> if format_dict['type'] is None or format_dict['type'] in 'gG':
> 
> That "fixes" this particular exception, but since the format specifier
> is invalid, it produces nonsense. I think Decimal's format parser needs
> to detect this as an error.

Do you mean that zero significant digits are invalid or that the conversion
specifier cannot be omitted? If I look at the following, the intentions are
not quite clear to me:

'0.1    '

'0.1    '

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.1/decimal.py", line 3611, in __format__
    spec = _parse_format_specifier(specifier, _localeconv=_localeconv)
  File "/usr/lib/python3.1/decimal.py", line 5595, in _parse_format_specifier
    if format_dict['type'] in 'gG' or format_dict['type'] is None:
TypeError: 'in <string>' requires string as left operand, not NoneType

'    0.1'

1. Conversion specifier can be omitted if significant digits != 0.

2. Significant digits can be zero if conversion specifier is present.

3. Exception

4. float() accepts the format.

I would be in favour of making the conversion specifier mandatory - and
perhaps disallow zero significant digits in the case of 'g'.  If the
intention is to mimic the C Standard, zero significant digits should
probably be silently promoted to one.

In any case, float() and Decimal() should preferably behave identically.

P.S.:

Unrelated, but I just see that float() has the wrong default alignment.
History
Date User Action Args
2009-09-07 15:21:07skrahsetrecipients: + skrah, mark.dickinson, eric.smith
2009-09-07 15:21:05skrahlinkissue6850 messages
2009-09-07 15:21:05skrahcreate