decorating base methods

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexandru  Mosoi

    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(...)?
  • Duncan Booth

    #2
    Re: decorating base methods

    Alexandru Mosoi <brtzsnr@gmail. comwrote:
    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

    Comment

    Working...