Last active
December 7, 2018 01:03
-
-
Save marcuscaisey/8442ebbc6695291c48ba889dd08755e6 to your computer and use it in GitHub Desktop.
Basic class 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 classmethod_(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(class_, *args[1:], **kwargs) | |
else: | |
return method(class_, *args, **kwargs) | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment