Last active
December 7, 2018 01:03
-
-
Save marcuscaisey/767912acd2ff29738fe5b96fcca0fdbe to your computer and use it in GitHub Desktop.
Basic static method 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
import functools | |
def staticmethod_(method): | |
class_name = method.__qualname__.split(".")[0] | |
@functools.wraps(method) | |
def wrapper(*args, **kwargs): | |
class_ = globals()[class_name] | |
if isinstance(args[0], class_): | |
return method(*args[1:], **kwargs) | |
else: | |
return method(*args, **kwargs) | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment