I have a class defined below that has a class property called 'prop', and I want the docstring 'this is a property comment' to print out. The current behavior executes the getter for the property and prints 'getter'.
Is there a way to setup the class and its metaclass so I can type 'help(MyClass.prop)' and get the docstring?
class _Metaclass(type):
@property
def prop(cls):
"""this is a property comment"""
print("getter")
return 1
@prop.setter
def prop(cls,value):
print("setter")
class MyClass(metaclass=_Metaclass):
"""this is a class comment"""
def func():
"""this is a function comment"""
You have set a property on a metaclass. Thus when you do MyClass.prop you are actually executing the property on the MyClass class object. If this was on a normal class instead of a metaclass the docstring would be correctly defined from the getter method. Metaclasses are to classes as classes are to instances, if that helps you think about what's going on here. You should get the correct docstring from help(_Metaclass.prop).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With