Skip to content

Instantly share code, notes, and snippets.

@victorlei
victorlei / extend_class.py
Created July 10, 2013 18:12
Python decorator @extend_class allows to "add" methods to an existing class
def extend_class(cls):
"""
Given class cls, apply decorator @extend_class to function f so
that f becomes a regular method of cls:
>>> class cls: pass
>>> @extend_class(cls)