Re: Override a method but inherit the docstring

2009-07-28 Thread Shai
On Jul 26, 6:55 pm, a...@pythoncraft.com (Aahz) wrote: > > Nice!  Maybe stick this on the Cookbook? http://code.activestate.com/recipes/576862/ Thanks for the suggestion, Shai. -- http://mail.python.org/mailman/listinfo/python-list

Re: Override a method but inherit the docstring

2009-07-28 Thread Jean-Michel Pichavant
Shai wrote: On Jul 27, 5:05 pm, Jean-Michel Pichavant wrote: Ben Finney wrote: The docstring for ‘FooGonk.frobnicate’ is, intentionally, perfectly applicable to the ‘BarGonk.frobnicate’ method also. Yet in overriding the method, the original docstring is not associated with it.

Re: Override a method but inherit the docstring

2009-07-27 Thread Shai
On Jul 27, 5:05 pm, Jean-Michel Pichavant wrote: > Ben Finney wrote: > > > > The docstring for ‘FooGonk.frobnicate’ is, intentionally, perfectly > > applicable to the ‘BarGonk.frobnicate’ method also. Yet in overriding > > the method, the original docstring is not associated with it. > > I've also

Re: Override a method but inherit the docstring

2009-07-27 Thread Jean-Michel Pichavant
Ben Finney wrote: Howdy all, The following is a common idiom:: class FooGonk(object): def frobnicate(self): """ Frobnicate this gonk. """ basic_implementation(self.wobble) class BarGonk(FooGonk): def frobnicate(self): special_implemen

Re: Override a method but inherit the docstring

2009-07-26 Thread Aahz
In article <056f629b-aa63-458a-ae16-ac40a759e...@h11g2000yqb.googlegroups.com>, Shai wrote: > >class DocInherit(object): >""" >Docstring inheriting method descriptor > >The class itself is also used as a decorator >""" Nice! Maybe stick this on the Cookbook? -- Aahz (a...@pytho

Re: Override a method but inherit the docstring

2009-07-23 Thread Shai
On Jul 17, 10:52 am, Steven D'Aprano wrote: > > When the decorator is called, the function object is just a function > object, not a method, so there is no concept of "what class it is > destined for". > ... which points to the better solution: use a descriptor. With the doc_inherit decorator def

Re: Override a method but inherit the docstring

2009-07-17 Thread David Stanek
On Fri, Jul 17, 2009 at 3:52 AM, Steven D'Aprano wrote: > On Fri, 17 Jul 2009 12:58:48 +1000, Ben Finney wrote: > >>> Using a decorator in this manner requires repeating the super class >>> name.  Perhaps there is a way to get the bases of BarGonk, but I don't >>> think so, because at the time that

Re: Override a method but inherit the docstring

2009-07-17 Thread David Stanek
On Fri, Jul 17, 2009 at 2:58 AM, Peter Otten<__pete...@web.de> wrote: > Ben Finney wrote: > >> Howdy all, >> >> The following is a common idiom:: >> >>     class FooGonk(object): >>         def frobnicate(self): >>             """ Frobnicate this gonk. """ >>             basic_implementation(self.w

Re: Override a method but inherit the docstring

2009-07-17 Thread Ben Finney
Peter Otten <__pete...@web.de> writes: > Just thinking aloud: Write a patch for pydoc that looks up the > base-class documentation. That doesn't scale; I want the docstring to be discovered by the normal interface (the ‘__doc__’ attribute) by *every* tool that gathers docstrings from methods. Al

Re: Override a method but inherit the docstring

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 12:58:48 +1000, Ben Finney wrote: >> Using a decorator in this manner requires repeating the super class >> name. Perhaps there is a way to get the bases of BarGonk, but I don't >> think so, because at the time that the decorator is called, BarGonk is >> not yet fully defined.

Re: Override a method but inherit the docstring

2009-07-17 Thread Peter Otten
Ben Finney wrote: > Howdy all, > > The following is a common idiom:: > > class FooGonk(object): > def frobnicate(self): > """ Frobnicate this gonk. """ > basic_implementation(self.wobble) > > class BarGonk(FooGonk): > def frobnicate(self): >

Re: Override a method but inherit the docstring

2009-07-16 Thread Ben Finney
Paul McGuire writes: > Two ideas come to mind, the decorator way and the metaclass way. I am > not a guru at either, but these two examples work: I think the decorator idea is most attractive to me, since it can be applied per method. > # the decorator way > def inherit_docstring_from(cls): >

Re: Override a method but inherit the docstring

2009-07-16 Thread Paul McGuire
On Jul 16, 8:01 pm, Ben Finney wrote: > Howdy all, > > The following is a common idiom:: > >     class FooGonk(object): >         def frobnicate(self): >             """ Frobnicate this gonk. """ >             basic_implementation(self.wobble) > >     class BarGonk(FooGonk): >         def frobnica

Re: Override a method but inherit the docstring

2009-07-16 Thread Rhodri James
On Fri, 17 Jul 2009 02:01:49 +0100, Ben Finney wrote: Howdy all, The following is a common idiom:: class FooGonk(object): def frobnicate(self): """ Frobnicate this gonk. """ basic_implementation(self.wobble) class BarGonk(FooGonk): def frobni

Re: Override a method but inherit the docstring

2009-07-16 Thread Maxim Khitrov
On Thu, Jul 16, 2009 at 9:13 PM, Jean-Paul Calderone wrote: > On Fri, 17 Jul 2009 11:01:49 +1000, Ben Finney > wrote: >> >> Howdy all, >> >> The following is a common idiom:: >> >>   class FooGonk(object): >>       def frobnicate(self): >>           """ Frobnicate this gonk. """ >>           basic

Re: Override a method but inherit the docstring

2009-07-16 Thread Jean-Paul Calderone
On Fri, 17 Jul 2009 11:01:49 +1000, Ben Finney wrote: Howdy all, The following is a common idiom:: class FooGonk(object): def frobnicate(self): """ Frobnicate this gonk. """ basic_implementation(self.wobble) class BarGonk(FooGonk): def frobnicate(sel