[Python-il] Checking if an object is "atomically pickleable"
cool-rr at cool-rr.com
Fri Dec 24 00:35:04 IST 2010
On Tue, Nov 23, 2010 at 11:16 PM, cool-RR <cool-rr at cool-rr.com> wrote:
> On Tue, Nov 23, 2010 at 11:01 PM, Shai Berger <shai at platonix.com> wrote:
>> Hi Ram and all,
>> 1) To me, it makes more sense to define the property you seek on the
>> an object is "atomically unpicklable", or "inherently unpicklable", if it
>> cannot be pickled, for any value of its attributes.
> Yeah, I guess that makes more sense; However, I'd still like to present a
> positive function to the user (`is_atomically_pickleable`) and not a
> negative one. (`is_inherently_unpickleable`). But I wouldn't complain if I
> was given the latter :)
>> 2) I'm not sure how you'd characterize a good answer; I think Laurence
>> Gonsalves' answer on StackOverflow is quite good.
> Laurence's answer seems wrong to me. He's calling the pickler, and on
> consequence is that the pickler does the `__reduce__` dance, but that seems
> like overkill. I think this causes waste. (Probably doing the actual
> pickling of the object instead of just checking if it's possible.) Checking
> if an object is atomically pickleable should not involve the object at all;
> Only its type.
I released the `pickle_tools` module which does exactly what I asked for:
Here are its tests<https://github.com/cool-RR/GarlicSim/tree/master/garlicsim/test_garlicsim/test_general_misc/test_pickle_tools>
You can use it by installing `garlicsim` and doing `from
garlicsim.general_misc import pickle_tools`. The function I was talking
about in this thread is `is_atomically_pickleable`. Everything is explained
in the docstrings.
There is even a Python 3 version on the Python 3 fork of
So you can use it on Python 3 code.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-il