diff options
-rw-r--r-- | Include/pydebug.h | 2 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Misc/cheatsheet | 2 | ||||
-rw-r--r-- | Modules/main.c | 7 | ||||
-rw-r--r-- | Objects/dictobject.c | 14 | ||||
-rw-r--r-- | Objects/object.c | 1 | ||||
-rw-r--r-- | Python/bltinmodule.c | 5 |
7 files changed, 31 insertions, 3 deletions
diff --git a/Include/pydebug.h b/Include/pydebug.h index db3b656..3282dc1 100644 --- a/Include/pydebug.h +++ b/Include/pydebug.h @@ -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. diff --git a/Misc/cheatsheet b/Misc/cheatsheet index 1bd487a..5d002fa 100644 --- a/Misc/cheatsheet +++ b/Misc/cheatsheet @@ -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. diff --git a/Modules/main.c b/Modules/main.c index 2dbdfe9..7777db1 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -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; diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 7d6ff61..daf64e0 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -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; @@ -1706,6 +1706,16 @@ dict_has_key(register dictobject *mp, PyObject *key) } 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) { PyObject *key; @@ -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__}, diff --git a/Objects/object.c b/Objects/object.c index 9e25467..8de6723 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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. diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index a846377..cf47c30 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -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) { |