[Python-checkins] r55525 - in python/trunk: Include/pydebug.h Misc/NEWS Misc/cheatsheet Modules/main.c Objects/dictobject.c Objects/object.c Python/bltinmodule.c
neal.norwitz
python-checkins at python.org
Wed May 23 08:35:42 CEST 2007
Author: neal.norwitz
Date: Wed May 23 08:35:32 2007
New Revision: 55525
Modified:
python/trunk/Include/pydebug.h
python/trunk/Misc/NEWS
python/trunk/Misc/cheatsheet
python/trunk/Modules/main.c
python/trunk/Objects/dictobject.c
python/trunk/Objects/object.c
python/trunk/Python/bltinmodule.c
Log:
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.
Modified: python/trunk/Include/pydebug.h
==============================================================================
--- python/trunk/Include/pydebug.h (original)
+++ python/trunk/Include/pydebug.h Wed May 23 08:35:32 2007
@@ -21,6 +21,8 @@
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
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Wed May 23 08:35:32 2007
@@ -12,6 +12,9 @@
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.
Modified: python/trunk/Misc/cheatsheet
==============================================================================
--- python/trunk/Misc/cheatsheet (original)
+++ python/trunk/Misc/cheatsheet Wed May 23 08:35:32 2007
@@ -41,6 +41,7 @@
-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 @@
-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.
Modified: python/trunk/Modules/main.c
==============================================================================
--- python/trunk/Modules/main.c (original)
+++ python/trunk/Modules/main.c Wed May 23 08:35:32 2007
@@ -40,7 +40,7 @@
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 @@
-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_DebugFlag++;
break;
+ case '3':
+ Py_Py3kWarningFlag++;
+ break;
+
case 'Q':
if (strcmp(_PyOS_optarg, "old") == 0) {
Py_DivisionWarningFlag = 0;
Modified: python/trunk/Objects/dictobject.c
==============================================================================
--- python/trunk/Objects/dictobject.c (original)
+++ python/trunk/Objects/dictobject.c Wed May 23 08:35:32 2007
@@ -1688,7 +1688,7 @@
}
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 @@
}
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 @@
"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__},
Modified: python/trunk/Objects/object.c
==============================================================================
--- python/trunk/Objects/object.c (original)
+++ python/trunk/Objects/object.c Wed May 23 08:35:32 2007
@@ -29,6 +29,7 @@
#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.
Modified: python/trunk/Python/bltinmodule.c
==============================================================================
--- python/trunk/Python/bltinmodule.c (original)
+++ python/trunk/Python/bltinmodule.c Wed May 23 08:35:32 2007
@@ -144,6 +144,11 @@
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) {
More information about the Python-checkins
mailing list