Hi Robert,

On 28 Feb., 19:56, Robert Bradshaw <rober...@math.washington.edu>
wrote:
> If you add a "cdef object __doc__" member to that class, you should be
> able to assign to it.

I am afraid this is not true.

One is not able to assign it. __doc__ is read only, even if you define
it cpdef or :

sage: cython('''cdef class C:
....:     "Documentation of C"
....:     cpdef object __doc__
....:     ''')
sage: c = C()
sage: c?
...
    File: _mnt_local_king__sage_temp_mpc622_11271_tmp_0_spyx_0.pyx
    (starting at line 6) Documentation of C
sage: c.__doc__='other documentation'
Traceback (most recent call last)
...
AttributeError: '_mnt_local_king__sage_temp_mpc622_11271_tmp_0_spyx'
object attribute '__doc__' is read-only


Other attempt: We cdef (or cpdef, that doesn't matter here [I tested])
__doc__ and use methods to write to and read from it. Still, it
doesn't work.

sage: cython('''cdef class C:
....:     "Documentation of C"
....:     cpdef object __doc__
....:     def set_doc(self,s):
....:         self.__doc__=s
....:     def get_doc(self):
....:         return self.__doc__
....:     ''')
sage: c = C()
sage: c?
...
    File: _mnt_local_king__sage_temp_mpc622_11271_tmp_1_spyx_0.pyx
    (starting at line 6) Documentation of C
sage: c.set_doc('New documentation')
sage: c.get_doc()
'New documentation'
sage: c.__doc__
'File: _mnt_local_king__sage_temp_mpc622_11271_tmp_3_spyx_0.pyx
(starting at line 6)\nDocumentation of C'
sage: c?
...
    File: _mnt_local_king__sage_temp_mpc622_11271_tmp_1_spyx_0.pyx
    (starting at line 6) Documentation of C


So, even if you cdef (or cpdef) __doc__ and use a method to assign to
it, you would still not be able to use it for introspection.

Cheers,
Simon

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to