mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
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.
This commit is contained in:
parent
61c345fa37
commit
1832de4bc0
4 changed files with 11 additions and 7 deletions
|
@ -58,7 +58,7 @@ Options and arguments (and corresponding environment variables):\n\
|
||||||
static char *usage_2 = "\
|
static char *usage_2 = "\
|
||||||
-O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
|
-O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
|
||||||
-OO : remove doc-strings in addition to the -O optimizations\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\
|
-S : don't imply 'import site' on initialization\n\
|
||||||
-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
|
-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
|
||||||
-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
|
-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
|
||||||
|
@ -161,7 +161,11 @@ Py_Main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strcmp(_PyOS_optarg, "warn") == 0) {
|
if (strcmp(_PyOS_optarg, "warn") == 0) {
|
||||||
Py_DivisionWarningFlag++;
|
Py_DivisionWarningFlag = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (strcmp(_PyOS_optarg, "warnall") == 0) {
|
||||||
|
Py_DivisionWarningFlag = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strcmp(_PyOS_optarg, "new") == 0) {
|
if (strcmp(_PyOS_optarg, "new") == 0) {
|
||||||
|
@ -170,8 +174,8 @@ Py_Main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"-Q option should be "
|
"-Q option should be `-Qold', "
|
||||||
"`-Qold', `-Qwarn' or `-Qnew' only\n");
|
"`-Qwarn', `-Qwarnall', or `-Qnew' only\n");
|
||||||
usage(2, argv[0]);
|
usage(2, argv[0]);
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
|
|
||||||
|
|
|
@ -377,7 +377,7 @@ complex_classic_div(PyComplexObject *v, PyComplexObject *w)
|
||||||
{
|
{
|
||||||
Py_complex quot;
|
Py_complex quot;
|
||||||
|
|
||||||
if (Py_DivisionWarningFlag &&
|
if (Py_DivisionWarningFlag >= 2 &&
|
||||||
PyErr_Warn(PyExc_DeprecationWarning,
|
PyErr_Warn(PyExc_DeprecationWarning,
|
||||||
"classic complex division") < 0)
|
"classic complex division") < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -419,7 +419,7 @@ float_classic_div(PyObject *v, PyObject *w)
|
||||||
double a,b;
|
double a,b;
|
||||||
CONVERT_TO_DOUBLE(v, a);
|
CONVERT_TO_DOUBLE(v, a);
|
||||||
CONVERT_TO_DOUBLE(w, b);
|
CONVERT_TO_DOUBLE(w, b);
|
||||||
if (Py_DivisionWarningFlag &&
|
if (Py_DivisionWarningFlag >= 2 &&
|
||||||
PyErr_Warn(PyExc_DeprecationWarning, "classic float division") < 0)
|
PyErr_Warn(PyExc_DeprecationWarning, "classic float division") < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (b == 0.0) {
|
if (b == 0.0) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
"""fixdiv - tool to fix division operators.
|
"""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
|
This runs the script `yourscript.py' while writing warning messages
|
||||||
about all uses of the classic division operator to the file
|
about all uses of the classic division operator to the file
|
||||||
`warnings'. The warnings look like this:
|
`warnings'. The warnings look like this:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue