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
* built-in class function ignoring the property getter (some_func.__doc__ set to a property returns the property instead of invoking the getter)

Is the second issue also problematic or the built-ins are meant to ignore properties and there should be no fix? I think I'm misunderstanding something here.

Cheers, 
Marko





Le dim. 7 oct. 2018 à 17:37, Jonathan Fine <jfine2358@gmail.com> a écrit :
Hi Marko

You wrote:

> I just couldn't figure out how to make the __doc__ attribute of a function a getter. Is this a bug or am I making a mistake? If it's my mistake, is there any other way how to dynamically __doc__ a function or am I forced to set __doc__ of a function at the decoration time?

Thank you for your clear examples. I'm not sure, but I may have found
the problem.

As I recall, setting obj.attr to a property won't work. Instead, you
have to set type(obj).attr to the property. And now you come up
against a problem. You can't set __doc__ on the type 'function', nor
can you subclass the type 'function'.

>>> def fn(): pass
>>> type(fn)
<class 'function'>

>>> type(fn).__doc__
'function(code, globals[, name[, argdefs[, closure]]]) [snip]'

>>> type(fn).__doc__ = None
TypeError: can't set attributes of built-in/extension type 'function'

>>> class FN(type(fn)): pass
TypeError: type 'function' is not an acceptable base type

As I (more vaguely) recall, something was done recently to add a get
attribute property that works directly on objects, rather than on
instances of a class. But I've not been able to find it. Perhaps I
misunderstood PEP 562.

Some perhaps relevant URLs:
https://www.python.org/dev/peps/pep-0224/ Attribute Docstrings
https://www.python.org/dev/peps/pep-0549/ Instance Descriptors
https://www.python.org/dev/peps/pep-0562/ Module __getattr__ and __dir__
https://stackoverflow.com/questions/2447353/getattr-on-a-module

--
Jonathan