python decorator and interface

from functools import wraps

def interface (fn):
    @wraps
    def to_be_implemented (*args):
        raise Exception ("Interface '%s' is not implemented!" % fn.__name__)
    return to_be_implemented

class Foo (object):
    @interface
    def test (self): pass

class Bar(Foo):
    def test (self): pass

class Qux(Foo):
    pass

Bar().test()
Qux().test()

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

To submit your comment, click the image below where it asks you to...
Clickcha - The One-Click Captcha