Index: Objects/fileobject.c =================================================================== --- Objects/fileobject.c (revision 61635) +++ Objects/fileobject.c (working copy) @@ -2073,6 +2073,30 @@ "'U' cannot be combined with 'w' or '+' mode.\n" ); +PyObject * +PyFile_GetAttr(PyObject *obj, PyObject *name) +{ + if (Py_Py3kWarningFlag && + strcmp(PyString_AsString(name), "softspace") == 0 && + PyErr_WarnEx(PyExc_DeprecationWarning, + "file.softspace was removed in 3.x", 1) < 0) + return NULL; + else + return PyObject_GenericGetAttr(obj, name); +} + +int +PyFile_SetAttr(PyObject *obj, PyObject *name, PyObject *value) +{ + if (Py_Py3kWarningFlag && + strcmp(PyString_AsString(name), "softspace") == 0 && + PyErr_WarnEx(PyExc_DeprecationWarning, + "file.softspace was removed in 3.x", 1) < 0) + return -1; + else + return PyObject_GenericSetAttr(obj, name, value); +} + PyTypeObject PyFile_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "file", @@ -2090,9 +2114,9 @@ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ + PyFile_GetAttr, /* tp_getattro */ /* softspace is writable: we must supply tp_setattro */ - PyObject_GenericSetAttr, /* tp_setattro */ + PyFile_SetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ file_doc, /* tp_doc */ Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 61635) +++ Misc/NEWS (working copy) @@ -12,6 +12,8 @@ Core and builtins ----------------- +- Issue #2348: Raise a Py3k warning on file.softspace. + - Issue #2400: Allow relative imports to "import *". - Issue 1745. Backport print function with: Index: Lib/test/test_py3kwarn.py =================================================================== --- Lib/test/test_py3kwarn.py (revision 61635) +++ Lib/test/test_py3kwarn.py (working copy) @@ -1,7 +1,8 @@ import unittest import sys +import os from test.test_support import (catch_warning, TestSkipped, run_unittest, - TestSkipped) + TESTFN) import warnings if not sys.py3kwarning: @@ -94,6 +95,21 @@ with catch_warning() as w: self.assertWarning(sorted(lst, cmp), w, expected) + def test_file_softspace(self): + expected = "file.softspace was removed in 3.x" + f = open(TESTFN, 'w') + def setter(): + f.softspace = 42 + + try: + with catch_warning() as w: + self.assertWarning(f.softspace, w, expected) + with catch_warning() as w: + self.assertWarning(setter(), w, expected) + finally: + f.close() + os.remove(TESTFN) + def test_main(): run_unittest(TestPy3KWarnings)