Skip to content

Instantly share code, notes, and snippets.

@oakfang
Created October 6, 2015 07:45
Show Gist options
  • Save oakfang/db3f6955321e7b6b9bcf to your computer and use it in GitHub Desktop.
Save oakfang/db3f6955321e7b6b9bcf to your computer and use it in GitHub Desktop.
from pluginable import Pluginable
class MyClass(Pluginable):
pass
from mycls import MyClass
@MyClass.plugin
def foo(self):
return 5
from types import MethodType
class Pluginable(object):
@classmethod
def plugin(cls, f):
name = f.func_name
setattr(cls, name, MethodType(f, None, cls))
import mycls
import mycls_plugins
mc = mycls.MyClass()
print mc.foo() # prints 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment