On Thu, 16 May 2013 23:18:47 +0600, Nils Bruin <
bruin...@gmail.com>
wrote:
> 1] In python, a nondata descriptor is a descriptor that doesn't have
> its '__set__' slot filled. Such descriptors can be overridden by
> entries in the instance '__dict__'. One might expect that specifying a
> cython "property" without giving a "__set__" method would lead to such
> an entry, but it doesn't: It leads to a datadescriptor that cannot be
> overridden by instance attributes:
>
> %cython
> cdef class T(object):
> property B:
> def __get__(self):
> return 1
>
>
>>>> class S(T): pass
>>>> s=S()
>>>> s.B=10
> AttributeError: attribute 'B' of 'T' objects is not writable
>
> This mirrors the @property decorator in python but it makes it hard to
> specify nondata descriptors. Are there thoughts about how to make it
> more convenient to declare nondata descriptors
Cython does create nondata descriptor in this example.
The error occurs for a completely different reason: cdef classes don't
have a __dict__ slot, see
http://trac.cython.org/cython_trac/ticket/745.
AFAIK, you can only get __dict__ by subclassing, like:
cdef class _T: ... # no __dict__, fast property access
class T(_T): ... # has __dict__ and all properties from _T
Best regards,
Nikita Nemkin