summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-05-04 04:16:52 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-05-04 04:16:52 (GMT)
commit015dd821364f8c210baa9faf9d66dc766f9b591e (patch)
treecac3e7f79348bd48f10bb8b66f174d149febe5b8
parentd72312857e985efac3127ef9eabae7d526230d69 (diff)
downloadcpython-015dd821364f8c210baa9faf9d66dc766f9b591e.zip
cpython-015dd821364f8c210baa9faf9d66dc766f9b591e.tar.gz
cpython-015dd821364f8c210baa9faf9d66dc766f9b591e.tar.bz2
Somewhere along the way, the softspace attr of file objects became read-
only. Repaired, and added new tests to test_file.py.
-rw-r--r--Lib/test/test_file.py20
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/fileobject.c3
3 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index be1b2de..677dafc 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -5,6 +5,26 @@ from array import array
from test.test_support import verify, TESTFN, TestFailed
from UserList import UserList
+# verify expected attributes exist
+f = file(TESTFN, 'w')
+softspace = f.softspace
+f.name # merely shouldn't blow up
+f.mode # ditto
+f.closed # ditto
+
+# verify softspace is writable
+f.softspace = softspace # merely shouldn't blow up
+
+# verify the others aren't
+for attr in 'name', 'mode', 'closed':
+ try:
+ setattr(f, attr, 'oops')
+ except TypeError:
+ pass
+ else:
+ raise TestFailed('expected TypeError setting file attr %r' % attr)
+f.close()
+
# verify writelines with instance sequence
l = UserList(['1', '2'])
f = open(TESTFN, 'wb')
diff --git a/Misc/NEWS b/Misc/NEWS
index 05c9ce2..3ff9a64 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.3 beta 2?
Core and builtins
-----------------
+- The softspace attribute of file objects became read-only by oversight.
+ It's writable again.
+
Extension modules
-----------------
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 5b2267b..92cfa5b 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -1962,7 +1962,8 @@ PyTypeObject PyFile_Type = {
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
- 0, /* tp_setattro */
+ /* softspace is writable: we must supply tp_setattro */
+ PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
file_doc, /* tp_doc */