[Python-ideas] Adding `Unpicklable` to the `collections` module
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:
> > Recently I had the need to filter objects based on whether they're
> > or not:
> > I'm not sure what's a good way to check for a specific object whether
> > picklable.
> > <
> > led me to think: Maybe we should have an `Unpicklable` abstract base
> > in the `collections` module? Then various unpicklable classes, like
> > files or widgets, could inherit from this class to signify that they
> > be pickled.
> > What do you think?
> This sounds useful. I’d rather spell the ABC pickle.Picklable, though.
(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`.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas