[Python-ideas] Dynamic getting of __doc__ of a function

Steven D'Aprano steve at pearwood.info
Sun Oct 7 18:52:31 EDT 2018


On Sun, Oct 07, 2018 at 06:17:47PM +0200, Marko Ristin-Kaufmann wrote:
> Hi,
> @Jonathan: thanks! I'll have a look at your links.
> 
> So there are actually two issues if I understand correctly:
> * help() ignoring the property getter when invoked on an instance

Not just the property getter, but if you set instance.__doc__ to a 
string, help ignores that string too.


> * built-in class function ignoring the property getter (some_func.__doc__
> set to a property returns the property instead of invoking the getter)

Not just functions, it is all instances. Properties are only invoked if 
they are on the class object, not the instance.


py> class X:
...     pass
...
py> x = X()
py> x.spam = property(lambda self: "computed result")
py> x.spam
<property object at 0xb78b2d9c>
py> x.spam.__get__(x)
'computed result'



-- 
Steve


More information about the Python-ideas mailing list