Created
October 6, 2015 07:45
-
-
Save oakfang/db3f6955321e7b6b9bcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pluginable import Pluginable | |
class MyClass(Pluginable): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mycls import MyClass | |
@MyClass.plugin | |
def foo(self): | |
return 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from types import MethodType | |
class Pluginable(object): | |
@classmethod | |
def plugin(cls, f): | |
name = f.func_name | |
setattr(cls, name, MethodType(f, None, cls)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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