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
 
David Stanek  
View profile  
 More options Jul 17 2009, 8:21 am
Newsgroups: comp.lang.python
From: David Stanek <dsta...@dstanek.com>
Date: Fri, 17 Jul 2009 08:21:39 -0400
Local: Fri, Jul 17 2009 8:21 am
Subject: Re: Override a method but inherit the docstring
On Fri, Jul 17, 2009 at 3:52 AM, Steven

D'Aprano<st...@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 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.

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

>>>> def dec(func):
> ...     print type(func)
> ...     try:
> ...             print func.im_class
> ...     except:
> ...             print "no im_class"
> ...     return func
> ...
>>>> class Test(object):
> ...     @dec
> ...     def spam(self):
> ...             pass
> ...
> <type 'function'>
> no im_class
>>>> type(Test.spam)
> <type 'instancemethod'>
>>>> Test.spam.im_class
> <class '__main__.Test'>

> I suppose you could try to determine what namespace you're currently when
> the class is created, but that's surely going to be fragile and messy.

It isn't too bad. I got the idea to use the method's enclosing
scope[1] in my decorator[2] from DecoratorTools. I am working to
remove it because it make me sad, but it does work.

[1] http://code.google.com/p/snake-guice/source/browse/snakeguice/decorat...
[2] http://code.google.com/p/snake-guice/source/browse/snakeguice/decorat...

--
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek


 
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.