Re: [Pyobjc-dev] pickled Objective-C objects
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-02-24 07:15:50
|
On Sunday, Feb 23, 2003, at 22:13 Europe/Amsterdam, Just van Rossum wrote: > A couple of quick thoughts. > [...] > I noticed that unpickling a new style object causes cls.__new__ to be > called. This currently does not work for ObjC classes as they insist on > being allocated with alloc(). However, ObjC's alloc/init protocol is in > many ways equivalent to Python's __new__/__init__ protocol, so as a > first step towards supporting pickling, I propose to make __new__ an > alias for alloc, and move the "TypeError: Use class methods to > instantiate new Objective-C objects" exception to the __init__/tp_init > method. Calling an ObjC class will then still result in that exception, > while still properly supporting __new__. > Class clusters may be problematic here (in combination with pickling). If you create an NSArray you actually end up with a subclass of NSArray. This should be pickled as if it is an NSArray (Apple might replace the classes implementing NSArray by a completely different set of classes). BTW. I just tried to pickle some Cocoa objects using protocol version 2, and that didn't crash. It also didn't work correctly (of course): the Objective-C state isn't saved. Ronald |