[Pyobjc-dev] another odd problem
Brought to you by:
ronaldoussoren
From: Steven D. A. <st...@ne...> - 2003-08-09 17:54:06
|
Thanks to Ronald and Martina for their comments regarding the non-retained objects that acted as datasources for an NSComboBox. Setting those objects as instance variables in the controller object did indeed solve that problem. However, I have encountered another weird problem which seems like a possible bug. 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' However, if you modify the code to avoid inheriting from Foundation.NSObject, you get the expected behavior: import Foundation class ListManager: def init( self ): return self def key_for_index( self, index ): print "INDEX = ", index class foo( ListManager ): def init( self ): ListManager.init( self ) return self i = foo() 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 ) The result: >>> 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 ) INDEX = 5 [...] After playing around with this awhile, I moved Foundation.NSObject to the ListManager class and now it seems to work. But is it a bug that the code in the first example above fails to work? -- Steven D. Arnold st...@ne... "One has a moral responsibility to disobey unjust laws." Martin Luther King News and Opinion Covering Free-Speech Issues in Media & Technology: http://prime.neosynapse.net:8080/index.php |