Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 13th, 2008, 10:35 AM
Alexandru Mosoi
Guest
 
Posts: n/a
Default decorating base methods

I want to derive a base class, such that some methods are decorated.

The only thing I have in mind is:

class Base(object):
def A(self, x): pass
def B(self, y): pass

class Derived(Base):
@decorator
def A(self, x): Base.A(self, x)

Is this correct approach? How can avoid call to Base.A(...)?
  #2  
Old August 13th, 2008, 12:55 PM
Duncan Booth
Guest
 
Posts: n/a
Default Re: decorating base methods

Alexandru Mosoi <brtzsnr@gmail.comwrote:
Quote:
I want to derive a base class, such that some methods are decorated.
>
The only thing I have in mind is:
>
class Base(object):
def A(self, x): pass
def B(self, y): pass
>
class Derived(Base):
@decorator
def A(self, x): Base.A(self, x)
>
Is this correct approach? How can avoid call to Base.A(...)?
Decorators are just syntactic sugar for calling a function, so for this
situation you probably want to ignore the sugar and use the decorator
directly:

class Derived(Base):
A = decorator(Base.A)

--
Duncan Booth http://kupuguy.blogspot.com
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles