[Python-Dev] file.writelines("foo\n","bar\n")
Thomas Wouters
thomas@xs4all.net
Mon, 28 May 2001 10:17:58 +0200
On Mon, May 28, 2001 at 09:40:54AM +0200, Martin v. Loewis wrote:
> When investigating calling conventions, I took a special look at
> METH_OLDARGS occurrences. While most of them look reasonable,
> file.writelines caught my attention. It has
> if (args == NULL || !PySequence_Check(args)) {
> PyErr_SetString(PyExc_TypeError,
> "writelines() argument must be a sequence of strings");
> return NULL;
> }
> Because it is a METH_OLDARGS method, you can do
> f=open("/tmp/x","w")
> f.writelines("foo\n","bar\n")
> With my upcoming patches, I'd replace this with METH_O, making this
> call illegal. Does anybody see a problem with that change in
> semantics?
Hell yeah. About the same problem as with the 'l.append("foo", "bar")'
problem in 1.5.2 -> [1.6, 2.x]. Oddly enough, this behaviour was added in
2.0, by converting a PyList_Check into a PySequence_Check:
$ python1.5
>>> file.writelines("foo\n", "bar\n", "baz", "baz", "baz\n")
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: writelines() requires list of strings
$ python2.0
>>> file.writelines("foo\n", "bar\n", "baz", "baz", "baz\n")
>>>
I do think we'll have to allow for this for one more release, with warnings
and all. It's extremely unlikely that anyone is using this, but changing it
without warning will definately not benifit 2.x's image wrt. stability ;P
If bugfix-releases were allowed to generate additional warnings, I'd add a
warning to 2.1.1....
--
Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!