-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Make ZeroDivisionError message more precise when floor-dividing by zero #119057
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
Comments
I was thinking about it yesterday. Perhaps a better solution would be dropping " or modulo" and leaving only "integer division by zero" for But if make the error message more specific (add "floor"), should not it also replace "division or modulo" with "division and modulo" for Whatever be done for integers, should be done for other numerical types. cc @mdickinson |
I see the value in harmonising the error messages, but I suspect we're all going to have different opinions on what the message should be. I'd personally drop the mention of the type, so that both So if we're changing this, I'd go for:
Would it be terrible to simply say |
+1 |
If it helps to harmonize the error messages, I support dropping also the type. The only difference may be if mixed types are involved, and the non-zero divisor is converted with losses to the zero of other type. But AFAIK there are no such cases in the core and the stdlib. In the end, all ZeroDivisionError exceptions may have the same error message. |
Ok, I agree. I will change my PR 👍 |
I think that I found one case that should not be changed: >>> 0 ** -1
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
0 ** -1
~~^^~~~
ZeroDivisionError: 0.0 cannot be raised to a negative power I would not want to see "division by zero" here. In fact, it will be just I also found that |
Agreed that the power case shouldn't be changed |
Feature or enhancement
Proposal:
When floor dividing by zero the error says "division or modulo" but while (non-floor) dividing by zero or modulo-ing (?) it is more specific saying "division" or "modulo". I would recommend changing this to "floor division" or "division" because it would help with knowing what exactly the error is talking about.
Thank You!
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: