The help(obj) function uses the type of obj to create its result. This is less than helpful when requesting help on a wrapped object. Since 3.5, inspect.signature() and inspect.from_callable() have a follow_wrapped option to get around similar issues. Adding the option to help() would prevent surprising behavior while still allowing current behavior to be used when needed. See http://stackoverflow.com/a/17705456/603136 for more.
To clarify, to my understanding the issue here is that when using a class as a decorator, and copying the wrapped function's __doc__ to self.__doc__ in __init__, help() will pick up the wrapper class's __doc__ rather than the instance's __doc__. For example: class Deco: "A decorator." def __init__(self, func): functools.update_wrapper(self, func) def __call__(self, *args, **kwargs): pass @Deco def double(n): "A function." return n * 2 help(double) will show "A decorator." rather than "A function." despite the use of functools.update_wrapper().
Hi @taleinat, Seems tha the wrapped func already has the __doc__ (in this case) copied. following your example: >>> double <test.Deco object at 0x7fe8d1fd5b20> >>> double.__doc__ 'A function' so help(double) will print correctly the double doc.
The issue was not that __doc__ was not copied, but that help() would use the class's __doc__ when called on an instance, even if that instance had its own __doc__. See the StackOverflow question for another example. You will not see this issue with the latest master branch, because it has already been resolved by PR GH-19479, as described and discussed in . Closing as "out of date".
History
Date
User
Action
Args
2022-04-11 14:58:44
admin
set
github: 74126
2020-09-26 06:54:20
taleinat
set
status: open -> closedresolution: out of datemessages: + stage: patch review -> resolved