[Python-Dev] Re: __all__ for pickle

Skip Montanaro skip@mojam.com (Skip Montanaro)
Fri, 16 Feb 2001 16:00:02 -0600 (CST)


    Jeremy> I was just testing Zope with the latest CVS python and ran into
    Jeremy> trouble with the pickle module.

    Jeremy> The module has grown an __all__ attribute:

    Jeremy> __all__ = ["PickleError", "PicklingError", "UnpicklingError", "Pickler",
    Jeremy>            "Unpickler", "dump", "dumps", "load", "loads"]

    Jeremy> This definition excludes a lot of other names defined at the
    Jeremy> module level, like all of the constants for the pickle format,
    Jeremy> e.g. MARK, STOP, POP, PERSID, etc.  It also excludes
    Jeremy> format_version and compatible_formats.

In deciding what to include in __all__ up to this point I have only had my
personal experience with the modules and the documentation to help me decide
what to include.  My initial assumption was that undocumented module-level
constants were not to be exported. 

I just added the following to my version of pickle:

    __all__.extend([x for x in dir() if re.match("[A-Z][A-Z0-9_]*$",x)])

That seems to catch all the defined constants.  Let me know if that's
sufficient in this case.

Skip