Skip to content

Commit

Permalink
PEP 238 documented -Qwarn as warning only for classic int or long
Browse files Browse the repository at this point in the history
division, and this makes sense.  Add -Qwarnall to warn for all
classic divisions, as required by the fixdiv.py tool.
  • Loading branch information
gvanrossum committed Sep 4, 2001
1 parent 61c345f commit 1832de4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Options and arguments (and corresponding environment variables):\n\
static char *usage_2 = "\
-O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
-OO : remove doc-strings in addition to the -O optimizations\n\
-Q arg : division options: -Qold (default), -Qwarn, -Qnew\n\
-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n\
-S : don't imply 'import site' on initialization\n\
-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
Expand Down Expand Up @@ -161,7 +161,11 @@ Py_Main(int argc, char **argv)
break;
}
if (strcmp(_PyOS_optarg, "warn") == 0) {
Py_DivisionWarningFlag++;
Py_DivisionWarningFlag = 1;
break;
}
if (strcmp(_PyOS_optarg, "warnall") == 0) {
Py_DivisionWarningFlag = 2;
break;
}
if (strcmp(_PyOS_optarg, "new") == 0) {
Expand All @@ -170,8 +174,8 @@ Py_Main(int argc, char **argv)
break;
}
fprintf(stderr,
"-Q option should be "
"`-Qold', `-Qwarn' or `-Qnew' only\n");
"-Q option should be `-Qold', "
"`-Qwarn', `-Qwarnall', or `-Qnew' only\n");
usage(2, argv[0]);
/* NOTREACHED */

Expand Down
2 changes: 1 addition & 1 deletion Objects/complexobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ complex_classic_div(PyComplexObject *v, PyComplexObject *w)
{
Py_complex quot;

if (Py_DivisionWarningFlag &&
if (Py_DivisionWarningFlag >= 2 &&
PyErr_Warn(PyExc_DeprecationWarning,
"classic complex division") < 0)
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ float_classic_div(PyObject *v, PyObject *w)
double a,b;
CONVERT_TO_DOUBLE(v, a);
CONVERT_TO_DOUBLE(w, b);
if (Py_DivisionWarningFlag &&
if (Py_DivisionWarningFlag >= 2 &&
PyErr_Warn(PyExc_DeprecationWarning, "classic float division") < 0)
return NULL;
if (b == 0.0) {
Expand Down
2 changes: 1 addition & 1 deletion Tools/scripts/fixdiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""fixdiv - tool to fix division operators.
To use this tool, first run `python -Qwarn yourscript.py 2>warnings'.
To use this tool, first run `python -Qwarnall yourscript.py 2>warnings'.
This runs the script `yourscript.py' while writing warning messages
about all uses of the classic division operator to the file
`warnings'. The warnings look like this:
Expand Down

0 comments on commit 1832de4

Please sign in to comment.