Re: [Pyobjc-dev] another odd problem
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-08-09 18:20:17
|
On Saturday, 9 August, 2003, at 19:53, Steven D. Arnold wrote: > Essentially, it seems classes that inherit from Foundation.NSObject do > not > correctly see methods in superclasses before the one that inherited > from > NSObject. However, note that dir does show the attribute! Consider > the > following code snippet: > > import Foundation > class ListManager: > def init( self ): > return self > def key_for_index( self, index ): > print "INDEX = ", index > > class foo( Foundation.NSObject, ListManager ): > def init( self ): > ListManager.init( self ) > return self > > i = foo.alloc().init() > if 'key_for_index' in dir( i ): > present = "is" > else: > present = "is not" > > print "dir shows that key_for_index %s an attribute of i" % present > i.key_for_index( 5 ) > > If you run this code, you get the following: > >>>> print "dir shows that key_for_index %s an attribute of i" % present > dir shows that key_for_index is an attribute of i >>>> i.key_for_index( 5 ) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > AttributeError: 'foo' object has no attribute 'key_for_index' > That is a bug, I'll look into it. Could you file a bug on SF, just in case I forget to fix it :-) There is one problem with your code: You call the init of only one of the superclasses. Because NSObject (obviously) doesn't know about Python's multiple inheritance your init should be more like: def init(self): self = NSObject.init(self) ListManager.init(self) return self Multiple inheritance with Objective-C objects is obviously not used very much. And then this bug after I told some people that mixin-classes would be a convenient way to add generic implementations for protocols (such as NSTableDataSource) to a class :-( Ronald |