-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decorators that change docstrings are not accounted for #117
Comments
Apparently the codebase has changed a bit. This is a test that works right now: import jedi
code = """
def wrap(func):
func.__doc__ = 'new'
return func
@wrap
def orig():
'''old'''
pass
orig("""
script = jedi.Script(code, 11, 5, None)
ifc = script.get_in_function_call()
ifc.docstring() Result:
|
Thank @dbrgn, I updated the issue and noted that |
The other thing will definitely not just start "magically" working. |
Don't sell yourself short David, you are a Jedi master after all. |
Jedis aren't what they used to be anymore :( Maybe using the |
Since I'm working on this kind of stuff now, I'm closing this in favor of #503. That issue is essentially the same than this one, but it is just about wraps, which is the remaining problem AFAIK. Changing arbitrary docstrings is definitely not going to be supported in the future, however changing docstrings with wraps is going to be supported. |
Works for me, thanks @davidhalter! |
It's been a few years since you wrote this issue, haha. :) |
Any and all work you do here is much appreciated my friend |
Hello @davidhalter , I am encountering an issue with |
Please use 0.16.0 and try again. |
I upgraded jedi to 0.16.0 (and parso is on 0.6.2), and still saw the same problem. (I used Spyder to do the checking, because the example code above seemed outdated.) Here is the script that I used: import functools
import time
from typeguard import typechecked
@typechecked
def func(a: int):
"""
A function
Parameters
----------
a : int
Something.
"""
print('someting')
def timer(func):
"""Print the runtime of the decorated function"""
@functools.wraps(func)
def wrapper_timer(*args, **kwargs):
start_time = time.perf_counter() # 1
value = func(*args, **kwargs)
end_time = time.perf_counter() # 2
run_time = end_time - start_time # 3
print(f"Finished {func.__name__!r} in {run_time:.4f} secs")
return value
return wrapper_timer
@timer
def waste_some_time(num_times):
"""
Waste some time
Parameters
----------
num_times : TYPE
DESCRIPTION.
Returns
-------
None.
"""
for _ in range(num_times):
sum([i**2 for i in range(10000)])
b = func(3) # Spyder is unable to retrieve its docstring
waste_some_time(1234) # Spyder is able to retrieve its docstring The docstring of the function It seems that it is something about Thanks! |
The docstring I get is
This is probably expected. The signature seems wrong, but I'm not really sure it is, because there are If you create a test script that helps a lot to reproduce. It also helps if you provide me with the actual output. |
I'm realizing that there's something wrong with However I found the issue and fixed it. |
Hi @davidhalter : Spyder was not able to extract the docstring of Do still I need to ping Spyder's authors to fix the usage of Thanks! |
It's as simple as:
Jedi's documentation is also available under https://jedi.readthedocs.org.
No it's fine. They use a language server implementation that probably does quite a few things wrong. I'll do the talking at some point when Jedi 1.0 is out :). |
The following behavior was observed using the latest dev branch a86cfa2.
The following code prints
old
instead ofnew
, meaning that the decorator was not accounted for.Result:
'orig()\n\nold'
UPDATE: The following now works:
Result:
'partial(func, *args, **keywords) - new function with partial application\nof the given arguments and keywords.'
The text was updated successfully, but these errors were encountered: