[issue45708] PEP 515-style formatting with underscores does not seem to work for Decimal

2021-11-04 Thread Sander Bollen


New submission from Sander Bollen :

Hello,

It appears that Decimal does not support PEP-515 style formatting with 
underscores as thousands separators. 

```
>>> from decimal import Decimal
>>> f"{Decimal('5000'):,}"
'5,000'
>>> f"{Decimal('5000'):_}"
Traceback (most recent call last):
  File "", line 1, in 
ValueError: invalid format string

```

This does work for all the other types mentioned in PEP515

```
>>> f"{5000:_}"
'5_000'
>>> f"{5000.0:_}"
'5_000.0'
>>> f"{complex(5000, 1):_}"
'(5_000+1j)'
```

I have tried this on python 3.8, 3.9 and 3.10 on a Mac.

--
components: Library (Lib)
messages: 405667
nosy: sndrtj
priority: normal
severity: normal
status: open
title: PEP 515-style formatting with underscores does not seem to work for 
Decimal
versions: Python 3.10, Python 3.8, Python 3.9

___
Python tracker 
<https://bugs.python.org/issue45708>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45708] PEP 515-style formatting with underscores does not seem to work for Decimal

2021-11-05 Thread Sander Bollen


Sander Bollen  added the comment:

Thanks for looking into this so swiftly!

As a user, I have found PEP515 to be worded a little ambiguously with regards 
to formatting using underscores as thousands separators. While it enumerates a 
collection of types as far as the constructor is concerned, it does not do so 
for formatting. Instead, it says to support `_` as thousands separator for 
formatting wherever `,` is allowed. Since `,` does work for Decimal, I have 
taken that to imply `_` should work for Decimal as well.

--

___
Python tracker 
<https://bugs.python.org/issue45708>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com