[Cython] [cython-users] Property + C-level attribute with the same name

Stefan Behnel stefan_ml at behnel.de
Sun Apr 14 08:43:28 CEST 2013


Nikita Nemkin, 13.04.2013 10:07:
> The following code exposes a C-level pointer as
> an integer property _with the same name_.
> ("public" won't work here because type conversion is required.)
> 
> cdef class A:
>     cdef void* attr
> 
>     property attr:
>         def __get__(self):
>             return <Py_intptr_t>self.attr
> 
> I have expected a naming error, but it works perfectly.
> Can I rely on this behavior or is it accidental?

I don't think it's intentional, and it certainly feels like a bug.

Although I agree that there might be use in it, it's hard to tell if this
is a special case that is useful enough to break the rules. A hugely more
general feature would be user defined type conversions, for example, which
would make "public" work here and this case could become the compile error
that I think it should be.

Other opinions?

Stefan



More information about the cython-devel mailing list