forked from VimPlug/jedi
Merge pull request #378 from ColinDuquesnoy/issue373
CompiledObject params, fixes #373
This commit is contained in:
@@ -554,6 +554,8 @@ class CallDef(object):
|
|||||||
if isinstance(self._executable, er.InstanceElement):
|
if isinstance(self._executable, er.InstanceElement):
|
||||||
return self._executable.params[1:]
|
return self._executable.params[1:]
|
||||||
return self._executable.params
|
return self._executable.params
|
||||||
|
elif self._executable.isinstance(er.compiled.CompiledObject):
|
||||||
|
return self._executable.params
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
sub = self._executable.get_subscope_by_name('__init__')
|
sub = self._executable.get_subscope_by_name('__init__')
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ from jedi import debug
|
|||||||
from jedi.parser.representation import Base
|
from jedi.parser.representation import Base
|
||||||
from jedi.cache import underscore_memoization
|
from jedi.cache import underscore_memoization
|
||||||
from jedi.evaluate.sys_path import get_sys_path
|
from jedi.evaluate.sys_path import get_sys_path
|
||||||
|
from jedi.parser.representation import Param
|
||||||
|
from jedi.parser.representation import SubModule
|
||||||
|
from jedi.evaluate.helpers import FakeName
|
||||||
from . import fake
|
from . import fake
|
||||||
|
|
||||||
|
|
||||||
@@ -20,6 +23,20 @@ class CompiledObject(Base):
|
|||||||
asserts = []
|
asserts = []
|
||||||
path = None # modules have this attribute - set it to None.
|
path = None # modules have this attribute - set it to None.
|
||||||
|
|
||||||
|
@property
|
||||||
|
def params(self):
|
||||||
|
params_str, ret = self._parse_function_doc()
|
||||||
|
tokens = params_str.split(',')
|
||||||
|
params = []
|
||||||
|
module = SubModule(self.get_parent_until().name)
|
||||||
|
# it seems like start_pos/end_pos is always (0, 0) for a compiled
|
||||||
|
# object
|
||||||
|
start_pos, end_pos = (0, 0), (0, 0)
|
||||||
|
for p in tokens:
|
||||||
|
params.append(Param(module, [FakeName(p.strip())], start_pos,
|
||||||
|
end_pos))
|
||||||
|
return params
|
||||||
|
|
||||||
def __init__(self, obj, parent=None):
|
def __init__(self, obj, parent=None):
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|||||||
+24
-1
@@ -10,10 +10,33 @@ from .helpers import cwd_at
|
|||||||
|
|
||||||
|
|
||||||
@cwd_at('test/extensions')
|
@cwd_at('test/extensions')
|
||||||
def test_compiled():
|
def test_completions():
|
||||||
if platform.architecture()[0] == '64bit':
|
if platform.architecture()[0] == '64bit':
|
||||||
package_name = "compiled%s%s" % sys.version_info[:2]
|
package_name = "compiled%s%s" % sys.version_info[:2]
|
||||||
sys.path.insert(0, os.getcwd())
|
sys.path.insert(0, os.getcwd())
|
||||||
if os.path.exists(package_name):
|
if os.path.exists(package_name):
|
||||||
s = jedi.Script("from %s import compiled; compiled." % package_name)
|
s = jedi.Script("from %s import compiled; compiled." % package_name)
|
||||||
assert len(s.completions()) >= 2
|
assert len(s.completions()) >= 2
|
||||||
|
|
||||||
|
|
||||||
|
@cwd_at('test/extensions')
|
||||||
|
def test_call_signatures_extension():
|
||||||
|
# with a cython extension
|
||||||
|
if platform.architecture()[0] == '64bit':
|
||||||
|
package_name = "compiled%s%s" % sys.version_info[:2]
|
||||||
|
sys.path.insert(0, os.getcwd())
|
||||||
|
if os.path.exists(package_name):
|
||||||
|
s = jedi.Script("from %s import compiled; compiled.Foo(" %
|
||||||
|
package_name)
|
||||||
|
defs = s.call_signatures()
|
||||||
|
for call_def in defs:
|
||||||
|
for param in call_def.params:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_call_signatures_stdlib():
|
||||||
|
code = "import math; math.cos("
|
||||||
|
s = jedi.Script(code)
|
||||||
|
defs = s.call_signatures()
|
||||||
|
for call_def in defs:
|
||||||
|
assert len(call_def.params) == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user