◐ Shell
clean mode source ↗

Issue 2199: cPickle error with gtk GEnum classes

cPickle has problems loading instances of gtk gobject.GEnum classes. 
gobject.GEnum is a subclass of int.  On the other hand pickle handles
those classes correctly.  Since cPickle is meant to be a faster version
of pickle this needs to be consider a bug.  

To test run the following script:

import gtk
##import pickle
import cPickle as pickle

simple_types = (
    bool,
    int,
    long,
    float,
    complex,
    basestring,
    type(None),
)


d = vars(gtk)
for (i,j) in d.iteritems():
    if isinstance(j, simple_types):
        try:
            s = pickle.dumps(j, pickle.HIGHEST_PROTOCOL)
            obj = pickle.loads(s)
        except (ValueError, TypeError):
            print j, type(j)

If you replace cPickle with pickle then the script runs fine.
Using slightly modified PyGObject (so that it gives more useful error
message in pyg_enum_new) and adding 'raise' in the end of attached
example, I got this:

<enum GTK_RC_TOKEN_LOWEST of type GtkRcTokenType> <class
'gtk._gtk.RcTokenType'>
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
ValueError: value out of range (294 not in 0..40)

Not sure what it means yet...