Re: [Pyobjc-dev] Three issues with PyObjC under Snow Leopard
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2009-10-06 13:04:53
|
On 5 Oct, 2009, at 5:59, David Eppstein wrote: > > (2) I have some apps I wrote using pyobjc under Leopard that broke > when I moved to Snow Leopard. The simplest is the one in > http://www.ics.uci.edu/~eppstein/LaTeX_Unicodifier.dmg.gz (that's the > app bundle but because it's Python the source is inside, and is quite > short). I don't want to ask anyone to debug my code for me, but I'm at > a bit of a loss: when I run it (either the app as I built it for 10.5, > or the same xcode project recompiled for a 10.6 intel target) I get a > mysterious message "10/4/09 8:28:13 PM LaTeX Unicodifier[13914] <type > 'exceptions.TypeError'>: Need 0 arguments, got 1" on the console and > it doesn't work: the UI appears, cmd-Q quits, but the actual app > that's supposed to be running the UI isn't there. I imagine that > somewhere there's a method that needs a signature and doesn't have > one, or something simple like that, but I can't seem to figure out how > to get xcode to show me who's raising the uncaught exception... There is an easy way to find the source of the exception: add 'objc.setVerbose(1)' to your 'main.py' file, just after the import of 'objc'. This will print exception tracebacks whenever exceptions cross the Python<->ObjC boundary. The problem is in the class Transformer, and in particular in the way you call the superclass initializer. Your code currently is: class Transformer (NSFormatter): def initWithSource_target_(self, source, target): self = NSFormatter.init(self) ... This is bad style, and furthermore doesn't work in 10.6 because 'NSFormatter.init' refers to the init method of the NSTransformer class (that is the classmethod '+init'). It happens to work in 10.5 because NSFormatter (or NSObject) doesn't have a +init method there. The right way to call a superclass method is using the super() function: class Transformer(NSFormatter): def initWithSource_target_(self,source,target): self = super(Transformer, self).init() if self is None: return None The call to super() isn't very pretty, but is the standard Python way of calling superclass methods in new-style classes. In Python 3.x the interface was cleaned up ("self = super().init()"), but until PyObjC supports Python 3.x we'll have to live with the current syntax. BTW. According to Apple the tests for 'self is None' is necesary, the superclass init might fail and return None. Ronald |