Commits

Ronald Oussoren  committed 8b44c4d

implement __reduce__ for set_proxy, simular to array_proxy

  • Participants
  • Parent commits 9c061ac

Comments (0)

Files changed (2)

File pyobjc-core/Lib/objc/_properties.py

     def _wrapped(self):
         return self.__wrapped.__getvalue__(self._parent)
 
-    #@_wrapped.setter
-    #def _wrapped(self, value):
-        #setattr(self._parent, self._name, value) 
+    def __reduce__(self):
+        # Ensure that the proxy itself doesn't get stored
+        # in pickles.
+        return _id, (self._wrapped,)
 
     def __getattr__(self, attr):
         return getattr(self._wrapped, attr)
 
-
     def __contains__(self, value):
         return self._wrapped.__contains__(value)
 

File pyobjc-core/PyObjCTest/test_set_property.py

 import objc
 from PyObjCTest.test_object_property import OCObserve
 import sys
+import pickle
 
 NSObject = objc.lookUpClass('NSObject')
 
             self.assertRaises(TypeError, o.aSet.__cmp__, o.aSet2)
             self.assertRaises(TypeError, o.aSet.__cmp__, {1})
 
+    def testPickling(self):
+        o = TestSetPropertyHelper.alloc().init()
+        o.aSet = {1, 2, 3}
+
+        self.assertFalse(isinstance(o.aSet, set))
+
+        p = pickle.dumps(o.aSet)
+        v = pickle.loads(p)
+        self.assertEqual(o.aSet, v)
+        self.assertTrue(isinstance(v, set))
 
 
 if __name__ == "__main__":