Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-15

Can't pickle named Enums, e.g. QtCore.Qt.SolidLine

    XMLWordPrintable

Details

    • c82ec2bcbdf4db8fc83fefaec6377aaf2bb3614b (pyside/pyside-setup/5.14)

    Description

      In this case, I get the error : "TypeError: can't pickle PenStyle objects".

      Since under the hood these enum values are just integers, I would imagine that implementing pickling shouldn't be too hard, and would be very useful.

      One thing that confuses me is that pickling fails, but I can use Qt.SolidLine as a key in a dictionary, which is usually only possible with pickleable objects, so maybe enum values are supposed to be pickleable and this is actually a bug? :

      from PySide2.QtCore import *
      d = { Qt.SolidLine : "Solid"}
      d.keys()
      [PySide.QtCore.Qt.PenStyle.SolidLine]
      
      import StringIO
      import pickle
      sio = StringIO.StringIO()
      pickle.dump(Qt.SolidLine, sio)
      Traceback (most recent call last):
        File "<pyshell#20>", line 1, in <module>
          pickle.dump(Qt.SolidLine, sio)
        File "C:\Python27\lib\pickle.py", line 1370, in dump
          Pickler(file, protocol).dump(obj)
        File "C:\Python27\lib\pickle.py", line 224, in dump
          self.save(obj)
        File "C:\Python27\lib\pickle.py", line 306, in save
          rv = reduce(self.proto)
        File "C:\Python27\lib\copy_reg.py", line 70, in _reduce_ex
          raise TypeError, "can't pickle %s objects" % base.__name__
      TypeError: can't pickle PenStyle objects
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            ctismer Christian Tismer
            simon_hibbs Simon Dominic Hibbs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes