Kaydet (Commit) 1832de4b authored tarafından Guido van Rossum's avatar Guido van Rossum

PEP 238 documented -Qwarn as warning only for classic int or long

division, and this makes sense.  Add -Qwarnall to warn for all
classic divisions, as required by the fixdiv.py tool.
üst 61c345fa
......@@ -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\
......@@ -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) {
......@@ -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 */
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment