This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: cPickle error with gtk GEnum classes
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: _doublep, loewis, pyscripter
Priority: normal Keywords:

Created on 2008-02-28 13:46 by pyscripter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg63091 - (view) Author: PyScripter (pyscripter) Date: 2008-02-28 13:46
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 = (

d = vars(gtk)
for (i,j) in d.iteritems():
    if isinstance(j, simple_types):
            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.
msg63106 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-02-28 21:29
Can you please investigate the details and report the cause of the problem?
msg63113 - (view) Author: Paul Pogonyshev (_doublep) Date: 2008-02-28 23:19
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
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...
msg63114 - (view) Author: Paul Pogonyshev (_doublep) Date: 2008-02-28 23:27
It doesn't seem 'pickle' itself works:

>>> import pickle
>>> import gtk
>>> s = pickle.dumps (gtk.RC_TOKEN_LOWEST, pickle.HIGHEST_PROTOCOL)
>>> pickle.loads (s)
__main__:1: Warning: cannot retrieve class for invalid (unclassed) type

** ERROR **: file pygenum.c: line 55 (pyg_enum_repr): assertion failed:
msg63125 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-02-29 06:08
This all look like a bug in pygtk to me, not like a bug in pickle/cPickle.
msg63148 - (view) Author: Paul Pogonyshev (_doublep) Date: 2008-02-29 22:45
Please close this issue.  It is a PyGObject bug, nothing to do with
Date User Action Args
2022-04-11 14:56:31adminsetgithub: 46452
2008-02-29 22:56:47loewissetstatus: open -> closed
resolution: not a bug
2008-02-29 22:45:47_doublepsetmessages: + msg63148
2008-02-29 06:08:03loewissetmessages: + msg63125
2008-02-28 23:27:08_doublepsetmessages: + msg63114
2008-02-28 23:19:49_doublepsetnosy: + _doublep
messages: + msg63113
2008-02-28 21:29:56loewissetnosy: + loewis
messages: + msg63106
2008-02-28 13:46:23pyscriptercreate