[Python-ideas] Adding `Unpicklable` to the `collections` module
Carl M. Johnson
cmjohnson.mailinglist at gmail.com
Wed Nov 24 01:53:49 CET 2010
On Tue, Nov 23, 2010 at 10:54 AM, Antoine Pitrou <solipsis at pitrou.net>wrote:
> > So `Pickleable` could have a `__subclasshook__` that would do the real
> > similarly to `Iterable`.
> The problem is that "doing the real work" can be CPU-intensive, and I
> don't think we would like isinstance() calls to become arbitrarily
> expensive (even if technically it's possible).
> An alternative is simply to catch the exception when trying to pickle a
> value. That implies that the type takes care to raise an exception if
> pickling would work but unpickling wouldn't, which is what file objects
> now do.
Yes, but isn't the advantage of having an ABC that you only have to "do the
real work" one time and after that the class will be registered as
Pickleable/NonPickleable? So, the first time you check a random class it
would see if it can call the Pickling methods and if so register that class
so future isinstance checks are virtually free and don't have to be dealt
with using try/except.
Maybe I'm misunderstanding something.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas