Skip to content

Match float zero-division message with CPython#7426

Merged
youknowone merged 1 commit intoRustPython:mainfrom
moreal:fix/fail-builtin-test-divmod
Mar 14, 2026
Merged

Match float zero-division message with CPython#7426
youknowone merged 1 commit intoRustPython:mainfrom
moreal:fix/fail-builtin-test-divmod

Conversation

@moreal
Copy link
Contributor

@moreal moreal commented Mar 14, 2026

This pull request lets RustPython raise zero-division error with same message with CPython.

# testfile.py
for op in ("//", "/", "%"):
    try:
        eval(f"1.{op}0.")
        print(op, "No Error")
    except Exception as e:
        print(op, "Error", e)

# before this pull request (073adbd8d): cargo run --release -q -- testfile.py
// Error float floordiv by zero
/ Error float division by zero
% Error float mod by zero

# on this pull request: cargo run --release -q -- testfile.py
// Error division by zero
/ Error division by zero
% Error division by zero

# python 3.14.3: python3 -- testfile.py
// Error division by zero
/ Error division by zero
% Error division by zero

Summary by CodeRabbit

  • Bug Fixes
    • Float division-by-zero error messages now display consistently across all division operations (division, modulo, floor division, and divmod).

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: a0acab0d-7b16-4e8e-b958-b7bc2b04e70d

📥 Commits

Reviewing files that changed from the base of the PR and between ed032d3 and 6f7a621.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_builtin.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/vm/src/builtins/float.rs

📝 Walkthrough

Walkthrough

Error messages for float division operations are standardized to use "division by zero" consistently across inner_div, inner_mod, inner_floordiv, and inner_divmod functions, replacing operation-specific prefixes in diagnostic output.

Changes

Cohort / File(s) Summary
Float Division Error Messages
crates/vm/src/builtins/float.rs
Standardized error messages for division-by-zero conditions across four float operations by removing operation-specific prefixes ("float division by zero" → "division by zero").

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested reviewers

  • youknowone

Poem

🐰 When floats must divide, no more confusion—
Just "division by zero," a clear conclusion!
Four functions now speak with one voice so clear,
Error messages harmonized, beautiful and sincere! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: aligning RustPython's float zero-division error messages with CPython's behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] test: cpython/Lib/test/test_builtin.py (TODO: 18)

dependencies:

dependent tests: (no tests depend on builtin)

[ ] test: cpython/Lib/test/test_decorators.py (TODO: 1)

dependencies:

dependent tests: (no tests depend on decorators)

[ ] test: cpython/Lib/test/test_marshal.py (TODO: 21)

dependencies:

dependent tests: (21 tests)

  • marshal: test_bool test_exceptions test_importlib test_inspect test_marshal test_zipimport
    • importlib._bootstrap_external: test_importlib test_unittest
      • modulefinder: test_importlib test_modulefinder
      • py_compile: test_argparse test_cmd_line_script test_compileall test_importlib test_multiprocessing_main_handling test_py_compile test_pydoc test_runpy
      • pydoc: test_enum
    • pkgutil: test_pkgutil
    • zipimport: test_importlib

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@moreal moreal marked this pull request as ready for review March 14, 2026 08:11
@youknowone youknowone merged commit d1ea359 into RustPython:main Mar 14, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants