fenics team mailing list archive
-
fenics team
-
Mailing list archive
-
Message #01045
Re: FEniCS Documentation -- PyDOLFIN doc-strings
On 28 July 2010 21:20, Johan Hake <johan.hake@xxxxxxxxx> wrote:
> [snip]
>
>> > How would you do that? I tried
>> >
>> > %extend dolfin::GenericVector
>> > {
>> > %pythoncode
>> > %{
>> > def data(self):
>> > generated_docstring_module.GenericVector.data.__doc__
>> > return self._data()
>> > %}
>> > }
>> >
>> > But it was only possible to have a "real" string, not a variable that was
>> > a str. Not sure why...
>>
>> Me neither, what I thought about doing was to generate the contents of
>> the *_post.i files from some source and then insert the docstring as a
>> literal string in the *_post.i file. But I decided that was too much
>> work.
>>
>> So what I will end up doing is to assign to the __doc__ members of
>> these functions in the dolfin/__init__.py (on import). This is
>> possible because Swig doesn't mess around with these functions but
>> just adds them to the module. If the *_post.i contains other than
>> simple functions/member functions we'll have to generate the *_post.i
>> files from some source.
>
> Would this work? I tried:
>
> class A(object):
> def jada(self):pass
>
> A.jada.__doc__ = "jada"
>
> but I got
>
> attribute '__doc__' of 'instancemethod' objects is not writable
Yes, the trick is to do:
A.__dict__["jada"].__doc__ = "jada"
So we just loop all classes in cpp and their dicts and try to assign
to __doc__, if we can't we'll assume that it is handled by the
docstrings.i. All other classes and functions in our Python layer have
correct docstrings by construction.
> I am still on vacation, which mean that I have been away from coding a bit so
> my Python is a bit rusty ;)
You're not much help then are you? ;)
Enjoy whatever remains of you holiday, looking forward to seeing you
back, more frequently, on the list.
Kristian
> Johan
>
Follow ups
References