From 2ee60675f1ce9604076a1ce087323894bbc80b5a Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Wed, 26 Feb 2014 13:51:40 +0100 Subject: [PATCH 1/6] Add a test call_signatures for compiled modules Should fail --- test/test_compiled.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/test_compiled.py b/test/test_compiled.py index c783a3e2..0c266897 100644 --- a/test/test_compiled.py +++ b/test/test_compiled.py @@ -10,10 +10,24 @@ from .helpers import cwd_at @cwd_at('test/extensions') -def test_compiled(): +def test_completions(): 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." % package_name) assert len(s.completions()) >= 2 + + +@cwd_at('test/extensions') +def test_call_signatures(): + # 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 \ No newline at end of file From da27ce4d7caac77bc4f05957fea67e93a86ce336 Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Wed, 26 Feb 2014 13:52:46 +0100 Subject: [PATCH 2/6] Execute test only on 64bit platforms --- test/test_compiled.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/test_compiled.py b/test/test_compiled.py index 0c266897..b87ee7cb 100644 --- a/test/test_compiled.py +++ b/test/test_compiled.py @@ -21,13 +21,13 @@ def test_completions(): @cwd_at('test/extensions') def test_call_signatures(): - # 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 \ No newline at end of file + 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 \ No newline at end of file From 725e55485af2ed1fce53502b481a4336078b70f7 Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Wed, 26 Feb 2014 13:53:09 +0100 Subject: [PATCH 3/6] Add params property to compiled object --- jedi/evaluate/compiled/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index 2c604e9f..a82fda7f 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -11,6 +11,9 @@ from jedi import debug from jedi.parser.representation import Base from jedi.cache import underscore_memoization 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 @@ -20,6 +23,20 @@ class CompiledObject(Base): asserts = [] 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): self.obj = obj self.parent = parent From d5ba683756c604623a95c99330c80261eaa5c367 Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Wed, 26 Feb 2014 13:53:35 +0100 Subject: [PATCH 4/6] Fix api.classes.CallDef.params We need to check for compiled objects --- jedi/api/classes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 83da30f0..82c28c5c 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -554,6 +554,8 @@ class CallDef(object): if isinstance(self._executable, er.InstanceElement): return self._executable.params[1:] return self._executable.params + elif self._executable.isinstance(er.compiled.CompiledObject): + return self._executable.params else: try: sub = self._executable.get_subscope_by_name('__init__') From b56c1cb1185c8d20276688f29509947cb46a26d4 Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Wed, 26 Feb 2014 14:21:52 +0100 Subject: [PATCH 5/6] Add test with standard lib math.cos( should return --- test/test_compiled.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/test_compiled.py b/test/test_compiled.py index b87ee7cb..8ea00e80 100644 --- a/test/test_compiled.py +++ b/test/test_compiled.py @@ -20,7 +20,8 @@ def test_completions(): @cwd_at('test/extensions') -def test_call_signatures(): +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()) @@ -30,4 +31,13 @@ def test_call_signatures(): defs = s.call_signatures() for call_def in defs: for param in call_def.params: - pass \ No newline at end of file + pass + + +def test_call_signatures_stdlib(): + code = "import math; math.cos(" + s = jedi.Script(code) + defs = s.call_signatures() + for call_def in defs: + for p in call_def.params: + assert str(p) == 'x' From 2c49a968a9263bbaa93c03938c8ce4545da890b4 Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Wed, 26 Feb 2014 14:29:27 +0100 Subject: [PATCH 6/6] Fix test (bad assert) --- test/test_compiled.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_compiled.py b/test/test_compiled.py index 8ea00e80..1e9d03c1 100644 --- a/test/test_compiled.py +++ b/test/test_compiled.py @@ -39,5 +39,4 @@ def test_call_signatures_stdlib(): s = jedi.Script(code) defs = s.call_signatures() for call_def in defs: - for p in call_def.params: - assert str(p) == 'x' + assert len(call_def.params) == 1