Drop redundant exception type prefix from float-to-int error messages#7763
Conversation
CPython raises `OverflowError("cannot convert float infinity to integer")`
and `ValueError("cannot convert float NaN to integer")` from
`Objects/floatobject.c::float___trunc___impl` and friends. The exception
type name is added by Python's traceback display layer; the message
itself should not duplicate it.
`try_to_bigint` was producing
`OverflowError("OverflowError: cannot convert ...")` etc., which made
`repr(e)` and any code path that inspects `str(e)` diverge from CPython.
Affects all 5 callers of `try_to_bigint`: `__int__`, `__floor__`,
`__ceil__`, `__round__` (no-arg), `__trunc__` — i.e. `int(x)`,
`math.floor/ceil/trunc(x)`, `round(x)` for non-finite floats.
Verified byte-identical with CPython 3.14.4 across 14 affected sites.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughError messages for float-to-integer conversion failures are standardized to match CPython's exact wording. The ChangesFloat Conversion Error Standardization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
thanks for the review ! |
|
@changjoon-park Just out of curiosity, are you finding bugs using fuzzing or other automated tools? |
Summary
CPython raises
OverflowError("cannot convert float infinity to integer")andValueError("cannot convert float NaN to integer")(Objects/floatobject.c). The exception type name is added by Python's traceback display layer; the message itself should not duplicate it.try_to_bigintwas producing the duplicated form:This makes
repr(e)and any code path that inspectsstr(e)diverge from CPython.Affected sites
All five callers of
try_to_bigintshare the message:int(x)float.__int__math.floor(x)float.__floor__math.ceil(x)float.__ceil__math.trunc(x)float.__trunc__round(x)(no ndigits)float.__round__Verification
cargo run --release -- -m test test_float test_builtin test_math test_int test_long test_complex test_decimal test_fractions test_statistics test_format test_re— 1,627 tests pass, 0 regressions.extra_tests/snippets/*.pypass under the CI feature set.A regression block is added to
extra_tests/snippets/builtin_float.pychecking the exact message text via a small_check_msg(call, exc_type, expected_msg)helper across all five callers.Summary by CodeRabbit
Release Notes
Bug Fixes
Tests