0

This question was raised some time ago: When I decorate a python function, VS Code shows the wrapper's help, instead of the function's , when hovered

Apparently it was fixed by PyLace. I have now the opposite problem: I want to include the docstring of the wrapper in the tooltip.

Decorator:


def magic:
  def wrapper:
     result = doSomeMagic()
     return result
  wrapper.__doc__ = f'{func.__doc__} and some other stuff'
  return wrapper

Now I have a function where I use the decorator:

@magic
def sayHello():
   '''A simple function to print Hello'''
   print("Hello")

If I call help(sayHello) I get back A simple function to print hello and some other stuff This is all good! But if I use the tooltip for the function hello it would just give me the docstring from the function: A simple function to print Hello but I want to have the wrapper docstring in the tooltip...

I tried to include in the wrapper:

func.__doc__ = wrapper.__doc__

No success so far. Does someone has an idea how to achieve this in VSCode or PyCharm? Is there a way to influence the shown tooltips?

Nlea
  • 1
  • 1
    Statically, VSCode doesn't know what `magic` does to `sayHello`. It would have to execute the code to see that a new docstring was provided. I don't know what it used to do to simulate that. – chepner Feb 24 '23 at 15:45
  • I was already afraid that it used some static analysis... but I am still wondering if it was possible because it seemed like it was from the old question – Nlea Feb 24 '23 at 15:49

0 Answers0