Skip to content

gh-119057: Use better error messages for zero division #119066

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

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented May 15, 2024

Now these two errors are very similar:

>>> 1 // 0
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    1 // 0
    ~~^^~~
ZeroDivisionError: integer floor division by zero
>>> 1.5 // 0
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    1.5 // 0
    ~~~~^^~~
ZeroDivisionError: float floor division by zero

Better wording is always welcome!


📚 Documentation preview 📚: https://cpython-previews--119066.org.readthedocs.build/

Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes look fine to me in principle. I think there's still some wrangling to do over the exact error messages we want - we need to resolve that on the issue.

@sobolevn sobolevn changed the title gh-119057: Use better error message for x // 0 gh-119057: Use better error messages for zero division May 16, 2024
@sobolevn sobolevn requested a review from mdickinson June 3, 2024 07:51
Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thank you! I searched for missing cases of both ZeroDivisionError and PyExc_ZeroDivisionError and didn't find any.

I'm a little horrified at how often we use ZeroDivisionError in random tests that have nothing to do with arithmetic, but that's another story ...

@sobolevn sobolevn merged commit 1d4c2e4 into python:main Jun 3, 2024
38 checks passed
@sobolevn
Copy link
Member Author

sobolevn commented Jun 3, 2024

Thanks a lot for the help and review! 👍
Usually we don't backport error messages changes.

I will open a new issue about ZeroDivisionError refactor.

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