Re: [Pyobjc-dev] Exceptions on calling super
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2009-09-29 20:36:34
|
Dirk, I cannot reproduce this with Python 2.6 and PyObjC HEAD, or with /usr/ bin/python on SL with its version of PyObjC. I've used the following scriptlet to test: #BEGIN from Cocoa import * NSApplication.sharedApplication() class SFWindow(NSWindow): def initWithContentRect_styleMask_backing_defer_(self, contentRect, styleMask, backing, defer): print "init" self = super(SFWindow, self).initWithContentRect_styleMask_backing_defer_( contentRect, styleMask, backing, defer) if self: pass # do stuff return self v = SFWindow.alloc().init() # EOF This prints "init" when run. Ronald On 20 Sep, 2009, at 13:16, Dirk Stoop wrote: >>> We recently moved our app from PyObjC 1.4 to 2.2 and now get a lot >>> of >>> exceptions like this: >>> >>> TypeError??: super(type, obj): obj must be an instance or subtype of >>> type >>> >>> These happen in any Python subclass of a Cocoa superclass, but only >>> occasionally. I'm not completely clear how to reproduce the issue, >>> but it only happens when we override an initializer and have a call >>> to: >>> >>> super(classNameOfOurSubClass, self).init() # or any other >>> initializer. >>> >>> Does anyone have a clue what might be going on? >> >> That message pretty clearly means that a classic class is getting >> injected somehow. Consider this:: >> >> class C: >> def foo(self): >> super(C, self) >> >> C().foo() >> >> Which version of Python? > > > Thanks for your reply :) > > We're using Python 2.5.4 and we don't have classic classes anywhere in > our app. > > The error message I get from the example you wrote is also different > from the one we're getting.. > > TypeError: super() argument 1 must be type, not classobj > > The one I get seems to explicitely state that the second argument is > not the type or a subtype of the first argument, yet the one I get > when I run your example just tells me that the second type can't be > 'the' old-style classobj. > > To get our app to stop crashing on this, I'll replace e.g. > > class SFWindow(NSWindow): > def initWithContentRect_styleMask_backing_defer_(self, > contentRect, styleMask, backing, defer): > self = super(SFWindow, > self).initWithContentRect_styleMask_backing_defer_(contentRect, > styleMask, backing, defer) > if self: > pass # do stuff > return self > > with: > > class SFWindow(NSWindow): > def initWithContentRect_styleMask_backing_defer_(self, > contentRect, styleMask, backing, defer): > self = > NSWindow.initWithContentRect_styleMask_backing_defer_(self, > contentRect, styleMask, backing, defer) > if self: > pass # do stuff > return self > > for now. I'm not planning on changing the superclasses of any of > these classes anyway, so the extra burden of maintaining this code is > well worth getting rid of these occasional crashes. > > Still very weird that this happens, I've tried to isolate the issue to > a particular situation, but all my efforts so far have failed and I > don't have time now to do more research. I'll post again here if/when > I've figured out the exact regression of this problem. > > - Dirk > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart > your > developing skills, take BlackBerry mobile applications to market and > stay > ahead of the curve. Join us from November 9-12, 2009. Register > now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |