pappasam / coc-jedi

coc.nvim wrapper for https://github.com/pappasam/jedi-language-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hover info for functools.wraps()-decorated function shows undecorated parameter list

smheidrich opened this issue · comments

I'm not sure if this is an issue in coc-jedi or Jedi itself, but I guess I'll ask here first and then we can propagate it "up" to Jedi if it's in their court.

When you have a function that is marked as wrapping another function with functools.wraps, the hovering info window for a call to the former shows the "correct" (in my opinion, anyway) docstring and function name, namely that of the wrapped function, but the "wrong" parameter list, namely that of the wrapping function (which will usually be just *args, **kwargs). Minimal reproducible example:

from functools import wraps

def f(x: int, y: float):
  "docstring of f"
  pass

@wraps(f)
def g(*ar, **kw):
  f(*ar, **kw)

g()

Moving the cursor into g() shows something like:

vim-hover

The expected result would be for it to show f(x: int, y: float) instead.

Now as I said, I'm not sure if this is an issue in coc-jedi or Jedi. I did some tests using Jedi itself and it seems the call signature shown by coc-jedi is what you get when you use the immediate result from Script.get_signatures(), whereas my "expected" result can be obtained by either re-resolving that signature via its own get_signatures() method or its get_type_hint() method (the latter is claimed in the Jedi docs to extract the signature from calls of this function, which probably isn't what we want here in general - but in this case it happens to be fine):

from jedi import Script

with open("example.py") as f:
  scr = Script(f.read())

sig = scr.get_signatures(11, 2)[0]

print(sig.to_string())                     # f(*ar, **kw)
print(sig.get_signatures()[0].to_string()) # f(x: int, y: float)
print(sig.get_type_hint())                 # f(x: int, y: float)

So I guess an easy fix would be to have coc-jedi apply the 2nd to last line to any function signatures that should go into the hover window, but perhaps it would be better if the "immediate" signature returned by Jedi was already the expected one?

Sorry, I just noitced this would be better as an issue for jedi-language-server. I'll reopen this there.