Answer the question
In order to leave comments, you need to log in
Python. Why does the decorator in the class not work?
It's just how the code works.
def typed(func):
def wrapper(*args):
print("in decor")
return func(*args)
return wrapper
@typed
def add(a: int, b: int) -> str:
return a + b
if __name__ == '__main__':
a = 4
b = 2
result = add(a, b)
print(result)
class MyClass:
def typed(func):
def wrapper(*args):
print("in decor")
return func(*args)
return wrapper
@typed
def add(a: int, b: int) -> str:
return a + b
if __name__ == '__main__':
a = 4
b = 2
result = MyClass().add(a, b)
print(result)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question