[Python-Dev] creating __all__ in extension modules

Thomas Wouters thomas@xs4all.net
Sun, 4 Feb 2001 01:42:09 +0100


On Sat, Feb 03, 2001 at 05:01:01PM -0600, Skip Montanaro wrote:
>     Tim> I'm afraid I find it hard to believe people will *keep* C-module
>     Tim> __all__ lists in synch with the code as the years go by.  If we're
>     Tim> going to do this, how about adding code to Py_InitModule4 that
>     Tim> sucks the non-underscore names out of its PyMethodDef argument and
>     Tim> automagically builds an __all__ attr?  Then nothing ever needs to
>     Tim> be fiddled by hand for C modules.

> The way it works now is that the module author inserts a call to
> _PyModuleCreateAllList at or near the end of the module's init func

>     /* initialize module's __all__ list */
>     _PyModule_CreateAllList(d);

Regardless of the use of this __all__ for C modules, this function has the
wrong name. If it's intended a real part of the API (and it should be, if
you want modules to use it) it shouldn't have a leading underscore.

As for the debate on the usefulness, I don't care much either way -- I don't
write or maintain that many C modules (exactly 0, in fact :-) and though I
see the logic in placing the responsibility with the C module writers, I
also know I greatly prefer writing and maintaining Python modules than C
modules. Placing the responsibility in the (Python) module doing the 'from
.. import *' sounds like a good enough idea to me. I'm also not sure what
other examples of its use are out there, other than os.py.

-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!