Skip to content

Commit fe67d97

Browse files
author
neal.norwitz
committed
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. git-svn-id: http://svn.python.org/projects/python/trunk@55525 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent b5c6b9b commit fe67d97

7 files changed

Lines changed: 31 additions & 3 deletions

File tree

Include/pydebug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ PyAPI_DATA(int) Py_DivisionWarningFlag;
2121
on the command line, and is used in 2.2 by ceval.c to make all "/" divisions
2222
true divisions (which they will be in 3.0). */
2323
PyAPI_DATA(int) _Py_QnewFlag;
24+
/* Warn about 3.x issues */
25+
PyAPI_DATA(int) Py_Py3kWarningFlag;
2426

2527
/* this is a wrapper around getenv() that pays attention to
2628
Py_IgnoreEnvironmentFlag. It should be used for getting variables like

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- Add -3 option to the interpreter to warn about features that are
16+
deprecated and will be changed/removed in Python 3.0.
17+
1518
- Patch #1686487: you can now pass any mapping after '**' in function
1619
calls.
1720

Misc/cheatsheet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Option Effect
4141
-h print this help message and exit
4242
-i Inspect interactively after running script (also PYTHONINSPECT=x) and
4343
force prompts, even if stdin appears not to be a terminal
44+
-m mod run library module as a script (terminates option list
4445
-O optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)
4546
-OO remove doc-strings in addition to the -O optimizations
4647
-Q arg division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
@@ -51,6 +52,7 @@ Option Effect
5152
-W arg : warning control (arg is action:message:category:module:lineno)
5253
-x Skip first line of source, allowing use of non-unix Forms of #!cmd
5354
-? Help!
55+
-3 warn about Python 3.x incompatibilities
5456
-c Specify the command to execute (see next section). This terminates the
5557
command option list (following options are passed as arguments to the command).
5658
the name of a python file (.py) to execute read from stdin.

Modules/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static char **orig_argv;
4040
static int orig_argc;
4141

4242
/* command line options */
43-
#define BASE_OPTS "c:dEhim:OQ:StuUvVW:xX?"
43+
#define BASE_OPTS "3c:dEhim:OQ:StuUvVW:xX?"
4444

4545
#ifndef RISCOS
4646
#define PROGRAM_OPTS BASE_OPTS
@@ -82,6 +82,7 @@ static char *usage_3 = "\
8282
-V : print the Python version number and exit (also --version)\n\
8383
-W arg : warning control; arg is action:message:category:module:lineno\n\
8484
-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
85+
-3 : warn about Python 3.x incompatibilities\n\
8586
file : program read from script file\n\
8687
- : program read from stdin (default; interactive mode if a tty)\n\
8788
";
@@ -267,6 +268,10 @@ Py_Main(int argc, char **argv)
267268
Py_DebugFlag++;
268269
break;
269270

271+
case '3':
272+
Py_Py3kWarningFlag++;
273+
break;
274+
270275
case 'Q':
271276
if (strcmp(_PyOS_optarg, "old") == 0) {
272277
Py_DivisionWarningFlag = 0;

Objects/dictobject.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
16881688
}
16891689

16901690
static PyObject *
1691-
dict_has_key(register dictobject *mp, PyObject *key)
1691+
dict_contains(register dictobject *mp, PyObject *key)
16921692
{
16931693
long hash;
16941694
dictentry *ep;
@@ -1705,6 +1705,16 @@ dict_has_key(register dictobject *mp, PyObject *key)
17051705
return PyBool_FromLong(ep->me_value != NULL);
17061706
}
17071707

1708+
static PyObject *
1709+
dict_has_key(register dictobject *mp, PyObject *key)
1710+
{
1711+
if (Py_Py3kWarningFlag &&
1712+
PyErr_Warn(PyExc_DeprecationWarning,
1713+
"dict.has_key() not supported in 3.x") < 0)
1714+
return NULL;
1715+
return dict_contains(mp, key);
1716+
}
1717+
17081718
static PyObject *
17091719
dict_get(register dictobject *mp, PyObject *args)
17101720
{
@@ -1978,7 +1988,7 @@ PyDoc_STRVAR(iteritems__doc__,
19781988
"D.iteritems() -> an iterator over the (key, value) items of D");
19791989

19801990
static PyMethodDef mapp_methods[] = {
1981-
{"__contains__",(PyCFunction)dict_has_key, METH_O | METH_COEXIST,
1991+
{"__contains__",(PyCFunction)dict_contains, METH_O | METH_COEXIST,
19821992
contains__doc__},
19831993
{"__getitem__", (PyCFunction)dict_subscript, METH_O | METH_COEXIST,
19841994
getitem__doc__},

Objects/object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ _Py_GetRefTotal(void)
2929
#endif /* Py_REF_DEBUG */
3030

3131
int Py_DivisionWarningFlag;
32+
int Py_Py3kWarningFlag;
3233

3334
/* Object allocation routines used by NEWOBJ and NEWVAROBJ macros.
3435
These are used by the individual routines for object creation.

Python/bltinmodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ builtin_apply(PyObject *self, PyObject *args)
144144
PyObject *func, *alist = NULL, *kwdict = NULL;
145145
PyObject *t = NULL, *retval = NULL;
146146

147+
if (Py_Py3kWarningFlag &&
148+
PyErr_Warn(PyExc_DeprecationWarning,
149+
"apply() not supported in 3.x") < 0)
150+
return NULL;
151+
147152
if (!PyArg_UnpackTuple(args, "apply", 1, 3, &func, &alist, &kwdict))
148153
return NULL;
149154
if (alist != NULL) {

0 commit comments

Comments
 (0)