-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Wrong PEP 515 parsing in decimal module (both C and Python versions) #88433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
While working on bpo-44258 I discover that the decimal module doesn't follow specification in PEP-515: "The current proposal is to allow one underscore between digits, and after base specifiers in numeric literals." (c) For example:
>>> float("1.1__1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: '1.1__1'
but
>>> from decimal import Decimal as C
>>> from _pydecimal import Decimal as P
>>> C("1.1__1")
Decimal('1.11')
>>> P("1.1__1")
Decimal('1.11') Maybe this requirement could be relaxed in PEP, but it seems - this was already discussed (see Alternative Syntax section). Hence, I think this is a bug. Patch for _pydecimal attached. |
There was some discussion of this on the python-dev mailing list at the time - see https://mail.python.org/pipermail/python-dev/2016-March/143556.html and the surrounding thread. It's probably best left alone. |
On Sun, May 30, 2021 at 08:20:14AM +0000, Mark Dickinson wrote:
I see.
PEP-515 is clear. If this is not a bug - it should be adjusted (as it |
Standards Track PEPs are historical documents; it's quite common that an actual implementation ends up diverging from a PEP in small ways after the PEP is accepted, and we don't usually do post-hoc updates in those situations. Possibly the decimal documentation could be updated, though. |
On Sun, May 30, 2021 at 08:32:40AM +0000, Mark Dickinson wrote:
Well, then I something misunderstood in PEP-0:
The current behaviour is documented. Do you mean we should document Regarding mail thread: I don't think that following the PEP will |
Yep, you're absolutely right. I should have said "after the PEP is final", not "after the PEP is accepted". PEP-515 was marked final on April 28th, 2017.
Thanks; I missed that. In that case, I don't think there's anything to do here documentation-wise. |
Sorry, I just don't think it's worth re-opening this discussion; Stefan Krah had good reasons (not just speed) to avoid implementing a precise interpretation of PEP-515 for Decimal. It would also be a backwards incompatible change at this point to start refusing strings that were previously accepted. As I said, it's probably best left alone at this point. |
On Sun, May 30, 2021 at 08:58:56AM +0000, Mark Dickinson wrote:
Unfortunately, neither correction can fix that the PEP does not
I'm not sure... Well, it's not so clear which strings are accepted previously (i.e. and The 1-st sentence doesn't specify the way underscores are removed. And |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: