If a decorator changes the function docstring, I would like to have the changed function doc displayed in the tooltip.
Nlea opened this issue · 5 comments
At the moment, Jedi makes an IDE like VS Code display the docstring of a function. Even though the function might have a decorator that changes the docstring of the function.
Example:
#Decorator
def magic:
def wrapper:
result = doSomeMagic()
return result
wrapper.__doc__ = f'{func.__doc__} and some other stuff’
func.__doc__ = wrapper.__doc__
return wrapper
#Function
@magic
def sayHello():
'''A simple function to print Hello'''
print("Hello")
If I call help(sayHello)
. I get the wrapper docs printed. If would use functools
that would change, but then I change the function docs insight the wrapper.
If I hover over the function sayHello
I get: “A simple function to print Hello”. What I would like to see is: “A simple function to print hello and some other stuff”, because the docstring was modified in the wrapper.
Is there a way that this could be included in the Jedi Logic? So that whenever a decorator changes the docstring of a function, the changed docstring is displayed instead of the static docstring from the function itself?
If you would be willing to accept a PR, I would be happy to work on it!
Did you try to use functools.wraps
? AFAIK Jedi respects that.
Hey @davidhalter ,
Thanks for your quick reply. Using functool.wraps doesn't change the tooltip.
#Decorator
def magic:
@wraps(func)
def wrapper:
result = doSomeMagic()
return result
func.__doc__ = f'{func.__doc__} and some other stuff’
return wrapper
#Function
@magic
def sayHello():
'''A simple function to print Hello'''
print("Hello")
This will have the output: "A simple function to print Hello". So it ignores the assigned docstring in the wrapper for the function.
If I assign inside the wrapper the wrapper.__doc__ = f'{func.__doc__} and some other stuff
’ I get the output "A simple function to print Hello and some other stuff".
But the Tooltip never changes and always displays the docstring from the function itself.
Oh ok, now I get it. I misunderstood you at first. This is something that I definitely do not want to support, because it's a side effect and it's very hard to deal with for very little gains. So, I'm sorry but this won't happen.
I however just realized that you might be using it with an Interpreter
, if that's the case and the __doc__
is not picked up correctly in that case, that's something you could potentially have a look at. What's not going to happen is static analysis on stuff like func.__doc__ =
. This is for performance reasons and other issues.
Since you @Nlea wrote that you are using an IDE like VS Code
, I'm pretty sure that this is a case that's not feasible to support. Sorry.