Newsgroups: comp.lang.python
From: Paul McGuire <pt...@austin.rr.com>
Date: Thu, 16 Jul 2009 18:35:05 -0700 (PDT)
Local: Thurs, Jul 16 2009 9:35 pm
Subject: Re: Override a method but inherit the docstring
On Jul 16, 8:01 pm, Ben Finney <ben+pyt...@benfinney.id.au> wrote:
> Howdy all, Two ideas come to mind, the decorator way and the metaclass way. I am > The following is a common idiom:: > class FooGonk(object): > class BarGonk(FooGonk): > The docstring for ‘FooGonk.frobnicate’ is, intentionally, perfectly > What is the most Pythonic, DRY-adherent, and preferably least-ugly not a guru at either, but these two examples work: # the decorator way class FooGonk(object): class BarGonk(FooGonk): bg = BarGonk() Prints: frobnicate(self) method of __main__.BarGonk instance Using a decorator in this manner requires repeating the super class # The metaclass way from types import FunctionType class DocStringInheritor(type): newClassDict[attributeName] = attribute return type.__new__(meta, classname, bases, newClassDict) class FooGonk2(object): class BarGonk2(FooGonk2): bg = BarGonk2() Prints: Help on method frobnicate in module __main__: frobnicate(self) method of __main__.BarGonk2 instance This metaclass will walk the list of bases until the desired Please use carefully, I just did the metaclass thing by following -- Paul You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||