Message92367
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. |
|
Date |
User |
Action |
Args |
2009-09-07 15:21:07 | skrah | set | recipients:
+ skrah, mark.dickinson, eric.smith |
2009-09-07 15:21:05 | skrah | link | issue6850 messages |
2009-09-07 15:21:05 | skrah | create | |
|