1

Python has the nice help() built-in that displays the doc string of an object. When I use it in the REPL passing a function in my module it nicely displays:

>>> help(mymodule.myfunction)
Help on function myfunction in module mymodule.main:

myfunction(parameter=False) -> Dict[str, str]
    Doc string of myfunction

But if I use a decorator like functools.@lru_cache the help function is somewhat confusing:

>>> help(mymodule.myfunction)
Help on _lru_cache_wrapper in module mymodule.main:

myfunction(parameter=False) -> Dict[str, str]
    Doc string of myfunction

The doc string is displayed, but the first line of the message is confusing for my users who aren't experienced Python programmers.

Note that I didn't create the decorator, it is from the functools module in stdlib. It looks like the solution of using functools.wraps won't work for me.

Can I do something to force the display of the first message even if the function has a decorator?

neves
  • 26,235
  • 24
  • 129
  • 157
  • Does this answer your question? [Python decorator handling docstrings](https://stackoverflow.com/questions/1782843/python-decorator-handling-docstrings) – SpearAndShield Jun 03 '22 at 16:14
  • 1
    @SpearAndShield thanks for the tip, but I think it doesn't apply to my case. I've updated the question – neves Jun 03 '22 at 18:16
  • 1
    The function *is the result of the decorator now*. If the people who created the function didn't add `wraps` (or manually do the equivalent) then I don't think there is anything you can do, other than maybe writing your own version of the decorator that does (maybe deferring to the one that doesn't do what you want) – juanpa.arrivillaga Jun 03 '22 at 18:22
  • 1
    but I think this is actually an issue with `help` – juanpa.arrivillaga Jun 03 '22 at 18:24

0 Answers0