[New-bugs-announce] [issue45739] The Python implementation of Decimal does not support the "N" format

Serhiy Storchaka report at bugs.python.org
Sat Nov 6 09:51:18 EDT 2021


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

The C implementation supports both formats "n" and "N". The Python implementation only supports format "n".

>>> from decimal import Decimal
>>> format(Decimal('1e100'), 'n')
'1e+100'
>>> format(Decimal('1e100'), 'N')
'1E+100'
>>> from _pydecimal import Decimal
>>> format(Decimal('1e100'), 'n')
'1e+100'
>>> format(Decimal('1e100'), 'N')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython/Lib/_pydecimal.py", line 3766, in __format__
    spec = _parse_format_specifier(specifier, _localeconv=_localeconv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/_pydecimal.py", line 6194, in _parse_format_specifier
    raise ValueError("Invalid format specifier: " + format_spec)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Invalid format specifier: N

----------
components: Library (Lib)
messages: 405861
nosy: facundobatista, mark.dickinson, rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: The Python implementation of Decimal does not support the "N" format
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45739>
_______________________________________


More information about the New-bugs-announce mailing list