[Python-Dev] Re: PyArg_ParseTuple

Guido van Rossum guido@python.org
Wed, 09 Jan 2002 10:30:50 -0500


> Offtopic again: PyArg_ParseTuple() is also nice for parsing a tuple
> in C code, which you for example receive as a result from calling a method.
> IIRC the only problem here is that it may throw weird error
> messages if the object is not a tuple.
> Instead of 'TypeError: unpack non-sequence' you get a
> 'SystemError: new style getargs format but argument is not a tuple'.
> 
> Should this be changed?

No, you should test for PyTuple_Check before calling
PyArg_ParseTuple.  Why do you think it's called that?

The other problem with this use, alas, is that when it catches a
legitimate error, the error it reports is confusing if you don't
change it.  Example:

>>> from socket import *
>>> s = socket(AF_INET, SOCK_STREAM)
>>> s.bind(())
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: getsockaddrarg() takes exactly 2 arguments (0 given)
>>> 

--Guido van Rossum (home page: http://www.python.org/~guido/)