On Mon, Nov 7, 2016 at 4:04 PM, Travis Scrimshaw <tsc...@ucdavis.edu> wrote:
>
>
> On Monday, November 7, 2016 at 7:26:57 AM UTC-6, Jeroen Demeyer wrote:
>>
>> On 2016-11-07 14:13, 'Martin R' via sage-devel wrote:
>> > I would like that these subclasses inherit the docstring of
>> > GrowthDiagram.__init__ (and a few other methods), but I do not know how
>> > to achieve this.
>>
>> sage: class B(A):
>> ....:     def __init__(self):
>> ....:         pass
>> ....:     __init__.__doc__ = A.__init__.__doc__
>>
>
> IIRC, another option would be to put it in the class-level doc, which is
> automatically passed down provided the subclass doesn't do its own
> class-level doc.

A very heavy-handed but also useful option would be to adopt something like:

http://docs.astropy.org/en/stable/api/astropy.utils.decorators.format_doc.html#astropy.utils.decorators.format_doc

I don't know how frequently very similar (if not identical) docstrings
come up in Sage, but this was frequent enough in Astropy to make this
decorator pretty useful.  It can do lots of stuff, but includes the
simple use case of copying the docstring from one method to another:

class B(A):
    @format_doc(A.__init__)
    def __init__(self):
        pass

Also +1 to the subclassing solution.

-- 
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