Created
October 13, 2010 16:05
-
-
Save mattvonrocketstein/624348 to your computer and use it in GitHub Desktop.
python metaclass AllStaticMethods
This file contains hidden or 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
| class AllStaticMethods(type): | |
| """ | |
| """ | |
| def __new__(cls, name, bases, dct, finished=True): | |
| """ | |
| NOTE: the 'finished' flag is used for chaining.. | |
| make sure you know what you're doing if you use it. | |
| """ | |
| is_nonprivate_function = lambda name,obj: (not name.startswith('_')) and is_function(obj) | |
| for x in dct: | |
| if is_nonprivate_function(x,dct[x]): | |
| dct[x] = staticmethod(dct[x]) | |
| if finished: | |
| return type.__new__(cls, name, bases, dct) | |
| else: | |
| return (cls, name, bases, dct) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment