You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fixes for verbose-decimal-constructor (FURB157) are sometimes incorrect in Ruff 0.7.3. Two of them change behavior and one introduces a syntax error.
First, negative zero should be kept as a string. int doesn’t have signed zeroes but Decimal does.
Second, the empty string should not be normalized to zero. The empty string signals an InvalidOperation, which can be trapped and converted to NaN or can cause an error. “Empty” here refers to the string after normalizing away white space and underscores.
Third, decimal int literals with too many digits cause syntax errors. The minimum maximum digit count is 640. If the integer-valued string argument to Decimal has over that many digits, it should stay a string.
$ { printf'from decimal import Decimal\nDecimal("1';printf 0%0.s {1..640};printf'")\n'; } >furb157.py
$ PYTHONINTMAXSTRDIGITS=640 python furb157.py
$ ruff check --isolated --preview --select FURB157 furb157.py --fixFound 1 error (1 fixed, 0 remaining).
$ PYTHONINTMAXSTRDIGITS=640 python furb157.py 2>&1| tail -n 1SyntaxError: Exceeds the limit (640 digits) for integer string conversion: value has 641 digits; use sys.set_int_max_str_digits() to increase the limit - Consider hexadecimal for huge integer literals to avoid decimal conversion limits.
The text was updated successfully, but these errors were encountered:
…r (FURB157)` (#14216)
This PR accounts for further subtleties in `Decimal` parsing:
- Strings which are empty modulo underscores and surrounding whitespace
are skipped
- `Decimal("-0")` is skipped
- `Decimal("{integer literal that is longer than 640 digits}")` are
skipped (see linked issue for explanation)
NB: The snapshot did not need to be updated since the new test cases are
"Ok" instances and added below the diff.
Closes#14204
The fixes for
verbose-decimal-constructor
(FURB157) are sometimes incorrect in Ruff 0.7.3. Two of them change behavior and one introduces a syntax error.First, negative zero should be kept as a string.
int
doesn’t have signed zeroes butDecimal
does.Second, the empty string should not be normalized to zero. The empty string signals an
InvalidOperation
, which can be trapped and converted to NaN or can cause an error. “Empty” here refers to the string after normalizing away white space and underscores.Third, decimal
int
literals with too many digits cause syntax errors. The minimum maximum digit count is 640. If the integer-valued string argument toDecimal
has over that many digits, it should stay a string.The text was updated successfully, but these errors were encountered: