Created
November 10, 2019 13:05
-
-
Save agronholm/8513b9ec9ce71384371b281ea984b5ef to your computer and use it in GitHub Desktop.
How do I properly wrap a class method?
This file contains hidden or 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
from functools import wraps | |
class A: | |
@classmethod | |
def method(cls): | |
print('cls = %s' % cls.__name__) | |
class B(A): | |
pass | |
def wrapper(func): | |
@wraps(func) | |
def inner(*args, **kwargs): | |
return func(*args, **kwargs) | |
return inner | |
A.method = wrapper(A.method) | |
B.method() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment