This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Improve ZeroDivisionError message for float and complex object
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.2, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: Retro, ezio.melotti, mark.dickinson
Priority: normal Keywords: needs review, patch

Created on 2009-12-11 22:17 by ezio.melotti, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
issue7482.patch ezio.melotti, 2009-12-11 22:17 Patch against trunk to improve the error messages
Messages (5)
msg96275 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-12-11 22:17
The current error messages for divisions by 0 of float and complex
object say "float/complex division", whereas for int and long is
"integer/long division by zero":
>>> 5/0
ZeroDivisionError: integer division or modulo by zero
>>> 5.0/0
ZeroDivisionError: float division

The attached patch adds "by zero" to the error messages of float and
complex in case of division, modulo or divmod by zero.

(Should I add tests to check the error message too?)
msg96603 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-19 14:03
So if we're going to change the error messages, it would be nice if the 
new error messages were grammatical English.  'complex division by zero' 
is fine, but e.g.  'float modulo by zero' doesn't really make sense.

Actually I'd be fine with 'float division by zero' for this, since there's 
an implicit division involved in computing a remainder.  Or perhaps 
something more verbose, like 'right-hand argument to modulo operation is 
msg96604 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-12-19 14:08
No, I don't think you should add tests for the error messages;  there 
should already be tests for the type of error, and that's enough.
msg96735 - (view) Author: Boštjan Mejak (Retro) Date: 2009-12-21 11:05
The patch is *almost* okay.

errno = 0;
 	div = c_quot(v->cval,w->cval); /* The raw divisor value. */
 	if (errno == EDOM) {
-		PyErr_SetString(PyExc_ZeroDivisionError, "complex remainder");
+		PyErr_SetString(PyExc_ZeroDivisionError, "complex modulo by zero");
 		return NULL;

It should be as expressed in the code above. In the patch, the fixed
string is "complex remainder by zero", but this is broken English. I
propose "complex modulo by zero". Please fix your patch and we're good.
msg99778 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-22 16:38
Fixed in r78319 (trunk) and r78320 (py3k). I just fixed the 'division' and left the 'modulo' and 'divmod' alone.
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51731
2010-02-22 16:38:09ezio.melottisetstatus: open -> closed
versions: - Python 2.6, Python 3.0, Python 3.1
messages: + msg99778

keywords: patch, patch, needs review
resolution: fixed
stage: patch review -> resolved
2009-12-21 11:05:01Retrosetnosy: + Retro

messages: + msg96735
versions: + Python 2.6, Python 3.0, Python 3.1
2009-12-19 14:08:52mark.dickinsonsetkeywords: patch, patch, needs review

messages: + msg96604
2009-12-19 14:03:42mark.dickinsonsetkeywords: patch, patch, needs review

messages: + msg96603
2009-12-11 22:17:27ezio.melotticreate