]> granicus.if.org Git - python/commitdiff
Add -3 option to the interpreter to warn about features that are
authorNeal Norwitz <nnorwitz@gmail.com>
Wed, 23 May 2007 06:35:32 +0000 (06:35 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Wed, 23 May 2007 06:35:32 +0000 (06:35 +0000)
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.

Include/pydebug.h
Misc/NEWS
Misc/cheatsheet
Modules/main.c
Objects/dictobject.c
Objects/object.c
Python/bltinmodule.c

index db3b65676d612e91f4f4e3935b42c703708b36c6..3282dc10ec467c4f3b134d75d22d2072ec41ded6 100644 (file)
@@ -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
index f65fece4f6e41ba1d417d848b4e621052ae09ec7..1b027f9aaa03f5ccf3338785a810e90e560c8f06 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.
 
index 1bd487a6dc59e2421da82b05920a3f297454ba03..5d002fa954659378ceb5f79fcfa9c2f8acfc3d36 100644 (file)
@@ -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.
index 2dbdfe9ab1cba6b4e607b3a4d177f4316995d331..7777db1a9610b178edeb8b19f83990a6f3fa2206 100644 (file)
@@ -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;
index 7d6ff610077eb1aea874433aa13431fe191688f6..daf64e01b7f235e8b80fb2bac564a0dc556be51d 100644 (file)
@@ -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__},
index 9e254676b4f2bee7bcadc11938d6672f35514991..8de67238154e44612c03cd806a06225b5fda1510 100644 (file)
@@ -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.
index a846377ec6b7b43ad8e1de58185ee731828a6fa3..cf47c30889bf995c87779a8af8d01de5eca19933 100644 (file)
@@ -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) {