Bugs item #785980, was opened at 2003-08-09 18:30
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=114534&aid=785980&group_id=14534
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Steven Arnold (stevena)
Assigned to: Nobody/Anonymous (nobody)
Summary: Inheriting from NSObject blocks visibility of attributes
Initial Comment:
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
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=114534&aid=785980&group_id=14534
|