[Python-ideas] Adding `Unpicklable` to the `collections` module

cool-RR cool-rr at cool-rr.com
Tue Nov 23 21:46:51 CET 2010

On Tue, Nov 23, 2010 at 10:25 PM, Éric Araujo <merwok at netwok.org> wrote:

> Hi,
> > Recently I had the need to filter objects based on whether they're
> picklable
> > or not:
> >
> >
> http://stackoverflow.com/questions/4080688/python-pickling-a-dict-with-some-unpicklable-items
> >
> > I'm not sure what's a good way to check for a specific object whether
> it's
> > picklable.
> >
> > <
> http://stackoverflow.com/questions/4080688/python-pickling-a-dict-with-some-unpicklable-items
> >This
> > led me to think: Maybe we should have an `Unpicklable` abstract base
> class
> > in the `collections` module? Then various unpicklable classes, like
> locks,
> > files or widgets, could inherit from this class to signify that they
> cannot
> > be pickled.
> >
> > What do you think?
> This sounds useful.  I’d rather spell the ABC pickle.Picklable, though.
> Regards
(Spelling note: People told me that "pickleable" (with an "e" in the middle)
makes more sense, so I'm using that now.)

The best solution might be to have both a `Pickleable` class and
an `Unpickleable` class. The reason to have the former is that
`isinstance(thing, Pickleable)` is more natural, and the reason to have the
latter is because we can't require people to inherit from `Pickleable` for
every single class that they define. (Since pickleability is the rule and
unpickleability is the exception.)

So `Pickleable` could have a `__subclasshook__` that would do the real work,
similarly to `Iterable`.


Ram Rachum
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20101123/8eae2968/attachment.html>

More information about the Python-ideas mailing list