Skip to content

Instantly share code, notes, and snippets.

@mattvonrocketstein
Created October 13, 2010 16:05
Show Gist options
  • Select an option

  • Save mattvonrocketstein/624348 to your computer and use it in GitHub Desktop.

Select an option

Save mattvonrocketstein/624348 to your computer and use it in GitHub Desktop.
python metaclass AllStaticMethods
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