[Python-Dev] Error checking in init<module> functions

Michael Hudson mwh at python.net
Fri Apr 22 17:05:29 CEST 2005


Thomas Heller <theller at python.net> writes:

> I always wondered why there usually is very sloppy error checking in
> init<module> functions.

Laziness, I presume...

> The problem is that when one of these things fail (although they are
> probably supposed to NOT fail) you end up with a module missing
> something, without any error message.

Err.  There's a call to PyErr_Occurred() after the init function is
called, so you should get an error message.

Carrying on regardless after an error runs the risk that the exception
will be cleared, of course.

> What would be the correct thing to do - I assume something like
>
>      if (PyModule_AddIntConstant(m, "MAX_WBITS", MAX_WBITS)) {
>          PyErr_Print();
>          return;
>      }

Just return, I think.

Cheers,
mwh

-- 
  The meaning of "brunch" is as yet undefined.
                                             -- Simon Booth, ucam.chat


More information about the Python-Dev mailing list