Created
April 19, 2015 10:27
-
-
Save ptsurko/97cc52d6eb75ddddfbd8 to your computer and use it in GitHub Desktop.
Python descriptors
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
class classmethod(object): | |
def __init__(self, func): | |
self.func = func | |
def __get__(self, instance, klass): | |
if klass is None: | |
klass = type(instance) | |
def newfunc(*args, **kwargs): | |
return self.func(klass, *args, **kwargs) | |
return newfunc | |
def __call__(self, func): | |
return classmethod(func) | |
class staticmethod(object): | |
def __init__(self, func): | |
self.func = func | |
def __get__(self, *_): | |
return self.func | |
def __call__(self, func): | |
return staticmethod(func) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment