[Python-Dev] PyDict_Size() error return

Guido van Rossum guido at python.org
Mon Feb 16 01:06:41 EST 2004

> PyDict_Size() sets an exception and returns 0 if it is passed NULL or a
> non-dict.  Is this a bug?  It seems like it should return -1, otherwise
> you'd have to distinguish between an empty dict and an error by calling
> PyErr_Occurred().

Looks like an (old) bug to me.  All other similar cases return NULL or
-1, and some calls to PyDict_Size() actually check for < 0.  (Many
calls don't check for errors, but those probably "know" that they are
dealing with a dict and maintain that invariant in other ways.)

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

More information about the Python-Dev mailing list