Skip to content

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

Merged
sobolevn merged 4 commits into
python:mainfrom
sobolevn:issue-119057
Jun 3, 2024
Merged

gh-119057: Use better error messages for zero division#119066
sobolevn merged 4 commits into
python:mainfrom
sobolevn:issue-119057

Conversation

@sobolevn

@sobolevnsobolevn commented May 15, 2024

Copy link
Copy Markdown
Member

Now these two errors are very similar:

>>>1//0Traceback (mostrecentcalllast):
File"<python-input-0>", line1, in<module>1//0~~^^~~ZeroDivisionError: integerfloordivisionbyzero
>>>1.5//0Traceback (mostrecentcalllast):
File"<python-input-1>", line1, in<module>1.5//0~~~~^^~~ZeroDivisionError: floatfloordivisionbyzero

Better wording is always welcome!


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

@mdickinsonmdickinson left a comment

Copy link
Copy Markdown
Member

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.

@sobolevnsobolevn changed the title gh-119057: Use better error message for x // 0gh-119057: Use better error messages for zero divisionMay 16, 2024
@sobolevn
sobolevn requested a review from mdickinsonJune 3, 2024 07:51

@mdickinsonmdickinson left a comment

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
MemberAuthor

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.

mliezun pushed a commit to mliezun/cpython that referenced this pull request Jun 3, 2024
barneygale pushed a commit to barneygale/cpython that referenced this pull request Jun 5, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
checkmkreporeplicatorBot pushed a commit to Checkmk/checkmk that referenced this pull request Aug 13, 2026
python/cpython#119066 harmonized
error messages for `/`, `//`, and `%`: They all just use
a plain "division by zero" message when needed.
Change-Id: Ia2c83e3242f5402c3b0093648bf49558c94e98fd
Sign up for freeto 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

@sobolevn@mdickinson