]> granicus.if.org Git - python/commitdiff
Somewhere along the way, the softspace attr of file objects became read-
authorTim Peters <tim.peters@gmail.com>
Sun, 4 May 2003 04:16:52 +0000 (04:16 +0000)
committerTim Peters <tim.peters@gmail.com>
Sun, 4 May 2003 04:16:52 +0000 (04:16 +0000)
only.  Repaired, and added new tests to test_file.py.

Lib/test/test_file.py
Misc/NEWS
Objects/fileobject.c

index be1b2de88e9aa893fabd4fde492a202d7f5f2c81..677dafc3f0dfa95a1d430f098c831e0cdafdfadf 100644 (file)
@@ -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')
index 05c9ce26ddfcd361ab54e116475fbb3ce5473338..3ff9a640fabd2c34d8ce8579d28345a875e3be71 100644 (file)
--- 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
 -----------------
 
index 5b2267b417d784a7b487a1abb5f810b70dcd42fc..92cfa5b35a94d0185e1f2d7cb44d26b95f59ce82 100644 (file)
@@ -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 */