Index: Python/sysmodule.c =================================================================== --- Python/sysmodule.c (revision 61762) +++ Python/sysmodule.c (working copy) @@ -226,6 +226,45 @@ exit status will be one (i.e., failure)." ); +static PyObject * +sys_enablepy3kwarn(PyObject *self, PyObject *args) +{ + Py_Py3kWarningFlag = 1; + Py_RETURN_NONE; + +} + +PyDoc_STRVAR(enablepy3kwarn_doc, +"enablepy3kwarn()\n\ +\n\ +Enable Py3k warnings." +); + +static PyObject * +sys_disablepy3kwarn(PyObject *self, PyObject *args) +{ + Py_Py3kWarningFlag = 0; + Py_RETURN_NONE; +} + +PyDoc_STRVAR(disablepy3kwarn_doc, +"disablepy3kwarn()\n\ +\n\ +Disable Py3k warnings." +); + +static PyObject * +sys_getpy3kwarn(PyObject *self, PyObject *args) +{ + return PyBool_FromLong(Py_Py3kWarningFlag); +} + +PyDoc_STRVAR(getpy3kwarn_doc, +"getpy3kwarn() -> bool\n\ +\n\ +Get whether Py3k warnings are being issued." +); + #ifdef Py_USING_UNICODE static PyObject * @@ -825,6 +864,9 @@ {"exc_clear", sys_exc_clear, METH_NOARGS, exc_clear_doc}, {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, {"exit", sys_exit, METH_VARARGS, exit_doc}, + {"enablepy3kwarn", sys_enablepy3kwarn, METH_NOARGS, enablepy3kwarn_doc}, + {"disablepy3kwarn", sys_disablepy3kwarn, METH_NOARGS, disablepy3kwarn_doc}, + {"getpy3kwarn", sys_getpy3kwarn, METH_NOARGS, getpy3kwarn_doc}, #ifdef Py_USING_UNICODE {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, METH_NOARGS, getdefaultencoding_doc}, @@ -1334,8 +1376,6 @@ PyString_FromString(Py_GetExecPrefix())); SET_SYS_FROM_STRING("maxint", PyInt_FromLong(PyInt_GetMax())); - SET_SYS_FROM_STRING("py3kwarning", - PyBool_FromLong(Py_Py3kWarningFlag)); SET_SYS_FROM_STRING("float_info", PyFloat_GetInfo()); #ifdef Py_USING_UNICODE Index: Doc/library/sys.rst =================================================================== --- Doc/library/sys.rst (revision 61762) +++ Doc/library/sys.rst (working copy) @@ -475,7 +475,27 @@ .. versionadded:: 2.3 +.. function:: getpy3kwarn() + Return the status of the Python 3.0 warning flag. It's ``True`` + when Python is started with the -3 option or enabled through + enablepy3kwarn. + + .. versionadded:: 2.6 + +.. function:: enablepy3kwarn() + + Enable Py3k warnings. + + .. versionadded:: 2.6 + +.. function:: disablepy3kwarn() + + Disable Py3k warnings. + + .. versionaded:: 2.6 + + .. data:: hexversion The version number encoded as a single integer. This is guaranteed to increase @@ -611,15 +631,6 @@ interpreter prepares to read a new interactive command; this can be used to implement a dynamic prompt. - -.. data:: py3kwarning - - Bool containing the status of the Python 3.0 warning flag. It's ``True`` - when Python is started with the -3 option. - - .. versionadded:: 2.6 - - .. data:: dont_write_bytecode If this is true, Python won't try to write ``.pyc`` or ``.pyo`` files on the Index: Lib/warnings.py =================================================================== --- Lib/warnings.py (revision 61762) +++ Lib/warnings.py (working copy) @@ -130,7 +130,7 @@ Warnings are omitted unless Python is started with the -3 option. """ - if sys.py3kwarning: + if sys.getpy3kwarn(): if category is None: category = DeprecationWarning warn(message, category, stacklevel+1) Index: Lib/test/regrtest.py =================================================================== --- Lib/test/regrtest.py (revision 61762) +++ Lib/test/regrtest.py (working copy) @@ -1194,9 +1194,6 @@ self.expected.add('test_sunaudiodev') self.expected.add('test_nis') - if not sys.py3kwarning: - self.expected.add('test_py3kwarn') - self.valid = True def isvalid(self): Index: Lib/test/test_py3kwarn.py =================================================================== --- Lib/test/test_py3kwarn.py (revision 61762) +++ Lib/test/test_py3kwarn.py (working copy) @@ -4,10 +4,6 @@ TestSkipped) import warnings -if not sys.py3kwarning: - raise TestSkipped('%s must be run with the -3 flag' % __name__) - - class TestPy3KWarnings(unittest.TestCase): def test_type_inequality_comparisons(self): @@ -120,7 +116,13 @@ def test_main(): - run_unittest(TestPy3KWarnings) + py3k_warn = sys.getpy3kwarn() + if not py3k_warn: + sys.enablepy3kwarn() + try: + run_unittest(TestPy3KWarnings) + finally: + sys.enablepy3kwarn() if py3k_warn else sys.disablepy3kwarn() if __name__ == '__main__': test_main()