Why the code bellow doesn’t work for python3.10 when the @property decorator
is applied on the method already decorated with @property
.
`
Define a decorator
def my_decorator(func):
def wrapper(*args, **kwargs):
print(“Decorator applied”)
return func(*args, **kwargs)
return wrapper
Apply the decorator over the method
class MyClass:
@my_decorator
@property
def x(self):
“””This is the docstring of x”””
return 42
Test the decorated method
obj = MyClass()
print(obj.x) # Output will be “Decorator applied” followed by “42”
print(obj.x.doc) # Output will be “This is the docstring of x”
`
It returns
for the first print:
<bound method my_decorator..wrapper of <main.MyClass object at 0x7e0b7943ebf0>>
And for the second print:
None
Everything worked fine with python3.8 except that I had to use functool.wraps