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

Re: Override a method but inherit the docstring

2009-07-27 Thread Shai
On Jul 27, 5:05 pm, Jean-Michel Pichavant jeanmic...@sequans.com 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-26 Thread Aahz
In article 056f629b-aa63-458a-ae16-ac40a759e...@h11g2000yqb.googlegroups.com, Shai s...@platonix.com 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

Re: Override a method but inherit the docstring

2009-07-23 Thread Shai
On Jul 17, 10:52 am, Steven D'Aprano st...@remove-this- cybersource.com.au 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.

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-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 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. Also,

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.wobble)     class

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'Apranost...@remove-this-cybersource.com.au 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

Override a method but inherit the docstring

2009-07-16 Thread Ben Finney
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_implementation(self.warble) The

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 ben+pyt...@benfinney.id.au 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):

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 Calderoneexar...@divmod.com wrote: On Fri, 17 Jul 2009 11:01:49 +1000, Ben Finney ben+pyt...@benfinney.id.au wrote: Howdy all, The following is a common idiom::   class FooGonk(object):       def frobnicate(self):           Frobnicate this

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 ben+pyt...@benfinney.id.au wrote: Howdy all, The following is a common idiom:: class FooGonk(object): def frobnicate(self): Frobnicate this gonk. basic_implementation(self.wobble) class

Re: Override a method but inherit the docstring

2009-07-16 Thread Paul McGuire
On Jul 16, 8:01 pm, Ben Finney ben+pyt...@benfinney.id.au 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):        

Re: Override a method but inherit the docstring

2009-07-16 Thread Ben Finney
Paul McGuire pt...@austin.rr.com 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