Stefan van Zwam
unread,Aug 29, 2012, 5:54:42 PM8/29/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cython...@googlegroups.com
Hi all,
Another day, another inexplicable behavior… First, the example (3 files):
# thing.pxd :
# ------
cdef class Thing:
cdef public __spea_ker
# thing.pyx :
# ------
cdef class Thing:
def __init__(self):
self.__spea_ker = 'Hey'
# subthing.py
# ------
from thing import Thing
class SubThing(Thing):
def test(self):
print self.__spea_ker
def test2(self):
print getattr(self, '__spea_ker')
In other words, a Python subclass of an extension type tries to access a public attribute of the cdef class/extension type. Now let's run it:
>>> from subthing import SubThing
>>> T = SubThing()
>>> T.test()
Traceback (most recent call last):
...
AttributeError: 'SubThing' object has no attribute '_SubThing__spea_ker'
>>> T.test2()
Hey
In other words, I can access the attribute with "getattr", but not with the dot-notation. The underscores in the attribute name play a role: without them, both test() and test2() work.
I don't know what to do with this, and have found my workaround, but figured it would be useful to leave a record somewhere in case others run into this.
Regards,
Stefan.