Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Override a method but inherit the docstring
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ben Finney  
View profile  
 More options Jul 16 2009, 10:58 pm
Newsgroups: comp.lang.python
From: Ben Finney <ben+pyt...@benfinney.id.au>
Date: Fri, 17 Jul 2009 12:58:48 +1000
Local: Thurs, Jul 16 2009 10:58 pm
Subject: Re: Override a method but inherit the docstring

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 inherit_docstring_from(cls):
>     def docstring_inheriting_decorator(fn):
>         fn.__doc__ = getattr(cls,fn.__name__).__doc__
>         return fn
>     return docstring_inheriting_decorator

That works, thank you.

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

Yes, I tried a few different ways, but within the decorator it seems the
function object is quite unaware of what class it is destined for.

--
 \     “We are human only to the extent that our ideas remain humane.” |
  `\                          —_Breakfast of Champions_, Kurt Vonnegut |
_o__)                                                                  |
Ben Finney


 
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.