mirror of https://github.com/python/cpython
Add -3 option to the interpreter to warn about features that are
deprecated and will be changed/removed in Python 3.0. This patch is mostly from Anthony. I tweaked some format and added a little doc.
This commit is contained in:
parent
5f2ba9f2b1
commit
8b2bfbc198
|
@ -21,6 +21,8 @@ PyAPI_DATA(int) Py_DivisionWarningFlag;
|
|||
on the command line, and is used in 2.2 by ceval.c to make all "/" divisions
|
||||
true divisions (which they will be in 3.0). */
|
||||
PyAPI_DATA(int) _Py_QnewFlag;
|
||||
/* Warn about 3.x issues */
|
||||
PyAPI_DATA(int) Py_Py3kWarningFlag;
|
||||
|
||||
/* this is a wrapper around getenv() that pays attention to
|
||||
Py_IgnoreEnvironmentFlag. It should be used for getting variables like
|
||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
|
|||
Core and builtins
|
||||
-----------------
|
||||
|
||||
- Add -3 option to the interpreter to warn about features that are
|
||||
deprecated and will be changed/removed in Python 3.0.
|
||||
|
||||
- Patch #1686487: you can now pass any mapping after '**' in function
|
||||
calls.
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ Option Effect
|
|||
-h print this help message and exit
|
||||
-i Inspect interactively after running script (also PYTHONINSPECT=x) and
|
||||
force prompts, even if stdin appears not to be a terminal
|
||||
-m mod run library module as a script (terminates option list
|
||||
-O optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)
|
||||
-OO remove doc-strings in addition to the -O optimizations
|
||||
-Q arg division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
|
||||
|
@ -51,6 +52,7 @@ Option Effect
|
|||
-W arg : warning control (arg is action:message:category:module:lineno)
|
||||
-x Skip first line of source, allowing use of non-unix Forms of #!cmd
|
||||
-? Help!
|
||||
-3 warn about Python 3.x incompatibilities
|
||||
-c Specify the command to execute (see next section). This terminates the
|
||||
command option list (following options are passed as arguments to the command).
|
||||
the name of a python file (.py) to execute read from stdin.
|
||||
|
|
|
@ -40,7 +40,7 @@ static char **orig_argv;
|
|||
static int orig_argc;
|
||||
|
||||
/* command line options */
|
||||
#define BASE_OPTS "c:dEhim:OQ:StuUvVW:xX?"
|
||||
#define BASE_OPTS "3c:dEhim:OQ:StuUvVW:xX?"
|
||||
|
||||
#ifndef RISCOS
|
||||
#define PROGRAM_OPTS BASE_OPTS
|
||||
|
@ -82,6 +82,7 @@ static char *usage_3 = "\
|
|||
-V : print the Python version number and exit (also --version)\n\
|
||||
-W arg : warning control; arg is action:message:category:module:lineno\n\
|
||||
-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
|
||||
-3 : warn about Python 3.x incompatibilities\n\
|
||||
file : program read from script file\n\
|
||||
- : program read from stdin (default; interactive mode if a tty)\n\
|
||||
";
|
||||
|
@ -267,6 +268,10 @@ Py_Main(int argc, char **argv)
|
|||
Py_DebugFlag++;
|
||||
break;
|
||||
|
||||
case '3':
|
||||
Py_Py3kWarningFlag++;
|
||||
break;
|
||||
|
||||
case 'Q':
|
||||
if (strcmp(_PyOS_optarg, "old") == 0) {
|
||||
Py_DivisionWarningFlag = 0;
|
||||
|
|
|
@ -1688,7 +1688,7 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
|
|||
}
|
||||
|
||||
static PyObject *
|
||||
dict_has_key(register dictobject *mp, PyObject *key)
|
||||
dict_contains(register dictobject *mp, PyObject *key)
|
||||
{
|
||||
long hash;
|
||||
dictentry *ep;
|
||||
|
@ -1705,6 +1705,16 @@ dict_has_key(register dictobject *mp, PyObject *key)
|
|||
return PyBool_FromLong(ep->me_value != NULL);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
dict_has_key(register dictobject *mp, PyObject *key)
|
||||
{
|
||||
if (Py_Py3kWarningFlag &&
|
||||
PyErr_Warn(PyExc_DeprecationWarning,
|
||||
"dict.has_key() not supported in 3.x") < 0)
|
||||
return NULL;
|
||||
return dict_contains(mp, key);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
dict_get(register dictobject *mp, PyObject *args)
|
||||
{
|
||||
|
@ -1978,7 +1988,7 @@ PyDoc_STRVAR(iteritems__doc__,
|
|||
"D.iteritems() -> an iterator over the (key, value) items of D");
|
||||
|
||||
static PyMethodDef mapp_methods[] = {
|
||||
{"__contains__",(PyCFunction)dict_has_key, METH_O | METH_COEXIST,
|
||||
{"__contains__",(PyCFunction)dict_contains, METH_O | METH_COEXIST,
|
||||
contains__doc__},
|
||||
{"__getitem__", (PyCFunction)dict_subscript, METH_O | METH_COEXIST,
|
||||
getitem__doc__},
|
||||
|
|
|
@ -29,6 +29,7 @@ _Py_GetRefTotal(void)
|
|||
#endif /* Py_REF_DEBUG */
|
||||
|
||||
int Py_DivisionWarningFlag;
|
||||
int Py_Py3kWarningFlag;
|
||||
|
||||
/* Object allocation routines used by NEWOBJ and NEWVAROBJ macros.
|
||||
These are used by the individual routines for object creation.
|
||||
|
|
|
@ -144,6 +144,11 @@ builtin_apply(PyObject *self, PyObject *args)
|
|||
PyObject *func, *alist = NULL, *kwdict = NULL;
|
||||
PyObject *t = NULL, *retval = NULL;
|
||||
|
||||
if (Py_Py3kWarningFlag &&
|
||||
PyErr_Warn(PyExc_DeprecationWarning,
|
||||
"apply() not supported in 3.x") < 0)
|
||||
return NULL;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "apply", 1, 3, &func, &alist, &kwdict))
|
||||
return NULL;
|
||||
if (alist != NULL) {
|
||||
|
|
Loading…
Reference in New Issue