Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 015dd82

Browse files
committed
Somewhere along the way, the softspace attr of file objects became read-
only. Repaired, and added new tests to test_file.py.
1 parent d723128 commit 015dd82

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lib/test/test_file.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55
from test.test_support import verify, TESTFN, TestFailed
66
from UserList import UserList
77

8+
# verify expected attributes exist
9+
f = file(TESTFN, 'w')
10+
softspace = f.softspace
11+
f.name # merely shouldn't blow up
12+
f.mode # ditto
13+
f.closed # ditto
14+
15+
# verify softspace is writable
16+
f.softspace = softspace # merely shouldn't blow up
17+
18+
# verify the others aren't
19+
for attr in 'name', 'mode', 'closed':
20+
try:
21+
setattr(f, attr, 'oops')
22+
except TypeError:
23+
pass
24+
else:
25+
raise TestFailed('expected TypeError setting file attr %r' % attr)
26+
f.close()
27+
828
# verify writelines with instance sequence
929
l = UserList(['1', '2'])
1030
f = open(TESTFN, 'wb')

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.3 beta 2?
1212
Core and builtins
1313
-----------------
1414

15+
- The softspace attribute of file objects became read-only by oversight.
16+
It's writable again.
17+
1518
Extension modules
1619
-----------------
1720

Objects/fileobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,8 @@ PyTypeObject PyFile_Type = {
19621962
0, /* tp_call */
19631963
0, /* tp_str */
19641964
PyObject_GenericGetAttr, /* tp_getattro */
1965-
0, /* tp_setattro */
1965+
/* softspace is writable: we must supply tp_setattro */
1966+
PyObject_GenericSetAttr, /* tp_setattro */
19661967
0, /* tp_as_buffer */
19671968
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
19681969
file_doc, /* tp_doc */

0 commit comments

Comments
 (0)