1
0
forked from VimPlug/jedi

A work in progress improvement for compiled signatures

This commit is contained in:
Dave Halter
2019-05-21 09:37:17 +02:00
parent 95cd8427f4
commit b17e7d5746
4 changed files with 43 additions and 12 deletions
+16 -11
View File
@@ -377,6 +377,21 @@ class DirectObjectAccess(object):
return inspect.isclass(self._obj) and self._obj != type
def get_signature_params(self):
return [
SignatureParam(
name=p.name,
has_default=p.default is not p.empty,
default=self._create_access_path(p.default),
has_annotation=p.annotation is not p.empty,
annotation=self._create_access_path(p.annotation),
kind_name=str(p.kind)
) for p in self._get_signature().parameters.values()
]
def get_signature_text(self):
return str(self._get_signature())
def _get_signature(self):
obj = self._obj
if py_version < 33:
raise ValueError("inspect.signature was introduced in 3.3")
@@ -397,22 +412,12 @@ class DirectObjectAccess(object):
raise ValueError
try:
signature = inspect.signature(obj)
return inspect.signature(obj)
except (RuntimeError, TypeError):
# Reading the code of the function in Python 3.6 implies there are
# at least these errors that might occur if something is wrong with
# the signature. In that case we just want a simple escape for now.
raise ValueError
return [
SignatureParam(
name=p.name,
has_default=p.default is not p.empty,
default=self._create_access_path(p.default),
has_annotation=p.annotation is not p.empty,
annotation=self._create_access_path(p.annotation),
kind_name=str(p.kind)
) for p in signature.parameters.values()
]
def negate(self):
return self._create_access_path(-self._obj)
+9
View File
@@ -5,6 +5,7 @@ import re
from functools import partial
from jedi import debug
from jedi.evaluate.utils import to_list
from jedi._compatibility import force_unicode, Parameter, cast_path
from jedi.cache import underscore_memoization, memoize_method
from jedi.evaluate.filters import AbstractFilter
@@ -111,6 +112,7 @@ class CompiledObject(Context):
def py__doc__(self):
return self.access_handle.py__doc__()
@to_list
def get_param_names(self):
try:
signature_params = self.access_handle.get_signature_params()
@@ -126,6 +128,13 @@ class CompiledObject(Context):
for signature_param in signature_params:
yield SignatureParamName(self, signature_param)
def get_signature_text(self):
try:
return self.access_handle.get_signature_text()
except ValueError:
params_str, ret = self._parse_function_doc()
return '(' + params_str + ')' + ret
def get_signatures(self):
return [BuiltinSignature(self)]