Hi!

I know that to @lazy_attribute supports Python classes written in a
Cython extension module. Also, I just tested that even a cdef class
compiles if @lazy_attribute is used:
    sage: cython("""
    ....: from sage.misc.lazy_attribute import lazy_attribute
    ....: from sage.structure.element cimport Element
    ....: cdef class MyElement(Element):
    ....:     @lazy_attribute
    ....:     def test(self):
    ....:         return 15
    ....: """)
    sage: e = MyElement(ZZ)

However, the lazy attribute doesn't work:
    sage: e.test
    Traceback (most recent call last):
    ...
    AttributeError: '..._spyx_0.MyElement' object has no attribute 'test'

I tried to "cdef public object test", but then it is impossible to also
define "test" as a lazy attribute (I suppose that's because Cython doesn't
want to have a method of the same name than a public attribute).

Something else that I tried: Define a function "test()" outside of the class
definition, "cdef public object test" in the class definition, and assign
lazy_attribute(test) to self.test during __init__. However, e.test would then
return the lazy_attribute, but would not return the number 15. Do I understand
correctly that  __get__ of the lazy_attribute would only be called if the
instance gets the lazy_attribute from the class?

Is there any way around?
Can one somehow define MyElement so that it is possible to assign the attribute
"test" to instances of MyElement while the class MyElement still has a method
"test"?

Best regards,
Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to