-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Align the grammar of the Decimal
string constructor with float
's
#128185
Comments
Whtat do you mean digits of a decimal? a Do you mean it's not specified on the docs? namely that you can have |
Yes, but the documentation on that seems outdated, since the grammar mentioned in the docs does not mention the underscore style. |
Well.. it says (emphasis mine)
So technically, it's fine? we don't want to overcharge the grammar I think. |
Well the grammar for the |
I see. I think it would be fine if we remove the mention of underscores in the text and add it to the grammar. Concerning leading and trailing whitespaces, I think this should be outside the grammar. WDYT? |
Decimal
string constructor with float
's
It's not. >>> Decimal('1__.__2')
Decimal('1.2')
>>> float('1__.__2')
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
float('1__.__2')
~~~~~^^^^^^^^^^^
ValueError: could not convert string to float: '1__.__2' That's known, see e.g. #88433
It's ok. So far we have an important module in the stdlib (called "this").
That's what it does: "If value is a string, it should conform to the decimal numeric string syntax after leading and trailing whitespace characters, as well as underscores throughout, are removed: [grammar follows]". |
What I meant is to remove "as well as underscores throughout" and put the but for decimals, we have so we could update |
I still think it's not a documentation issue, at least. If we leave current parsing intact, IMO it's better to be more vague in description on how exactly underscores are removed. Maybe it's ok to revisit of parsing decimal literals. Here is some motivation from Stefan Krah for current version:
But patch from #88433 doesn't look complex to me (if it's correct;-)). However, if current behavior will be changed - it should be properly deprecated first. On another hand, even after this - the decimal grammar will be slightly different from floatvalue: Python floats doesn't support signaling nan. Nor "diagnostic" information for nans. Also, current docs doesn't mention that case is insignificant. The specification says: "the characters in the strings accepted for infinity and nan may be in any case". Removing "easy" label as it's not an easy issue at all. |
The grammar does not cover the case with underscores between the digits of a Decimal. The PEP-515 introduced underscores for integers, floating-point numbers and decimals. The documentation for integers and floating-point numbers are updated to cover underscores, but the grammar documentation for the
Decimal
does not.Linked PRs
Decimal
string constructor withfloat
's #128315The text was updated successfully, but these errors were encountered: