
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? Regards, Martin

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!

[Martin v. Loewis]
... 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?
Guido won't, and if he had even a twinge of doubt, Thomas's explanation of how this bug was introduced in 2.0 would erase it. The list.append() docs were arguably unclear when that brouhaha hit, but there's nothing unclear about the file.writelines() docs. OTOH, the file.writelines() docs still say a list is required, not "a sequence" as the 2.0 (+ current) code actually implements. Hmm. Wonder whether writelines() should be generalized to allow an iterable object?

"Martin v. Loewis" <martin@loewis.home.cs.tu-berlin.de>
I took a special look at METH_OLDARGS occurrences.
Shouldn't all these be removed? I would have thought list.append was the last one! Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+

[Martin]
I took a special look at METH_OLDARGS occurrences.
[GregE]
Shouldn't all these be removed? I would have thought list.append was the last one!
I count 42 of them remaining, usually for 0-argument functions. METH_OLDARGS is faster than METH_VARARGS in that case, and the callee can distinguish between "called with nothing" and "called with something" under OLDARGS. However, they don't appear to catch keyword args:
{}.clear(2) # complains Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: function takes no arguments {}.clear(val=12, hohoho=666) # accepts nonsense silently
the-more-you-look-the-messier-it-gets-ly y'rs - tim

On Tue, 29 May 2001, Tim Peters wrote:
[Martin]
I took a special look at METH_OLDARGS occurrences.
[GregE]
Shouldn't all these be removed? I would have thought list.append was the last one!
I count 42 of them remaining, usually for 0-argument functions.
There are more than that; PyMethodDefs that don't put anything in that slot in the source are METH_OLDARGS too, and there are quite a few of them in Modules/ (there are *lots* in _cursesmodule.c, but also in many of the older modules - gl, rotor were easy to find). There are also quite a lot of functions that put literal zeros there, too. So METH_OLDARGS is far from dead, sadly. Cheers, M.
participants (5)
-
Greg Ewing
-
Martin v. Loewis
-
Michael Hudson
-
Thomas Wouters
-
Tim Peters