Created
June 27, 2012 14:55
-
-
Save carljm/3004616 to your computer and use it in GitHub Desktop.
pure Python implementation of the staticmethod decorator
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 StaticMethod(object): | |
def __init__(self, func): | |
self.func = func | |
def __get__(self, obj, cls): | |
return self.func | |
def staticmethod(func): | |
return StaticMethod(func) |
@dogewzy, it's Python descriptors protocol, pls see details in https://docs.python.org/3.7/reference/datamodel.html#object.__get__
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why staticmethod need tow params "obj" and "cls"??It seems useless