forked from VimPlug/jedi
Add Definition.execute, fixes #1076
This commit is contained in:
@@ -18,6 +18,8 @@ New APIs:
|
||||
- ``Signature.params -> List[ParamDefinition]``, ParamDefinition has the
|
||||
following attributes ``infer_default()``, ``infer_annotation()``,
|
||||
``to_string()``, and ``kind``.
|
||||
- ``Definition.execute() -> List[Definition]``, makes it possible to infer
|
||||
return values of functions.
|
||||
|
||||
|
||||
0.14.1 (2019-07-13)
|
||||
|
||||
@@ -398,6 +398,9 @@ class BaseDefinition(object):
|
||||
def get_signatures(self):
|
||||
return [Signature(self._evaluator, s) for s in self._name.infer().get_signatures()]
|
||||
|
||||
def execute(self):
|
||||
return _contexts_to_definitions(self._name.infer().execute_evaluated())
|
||||
|
||||
|
||||
class Completion(BaseDefinition):
|
||||
"""
|
||||
|
||||
@@ -442,3 +442,20 @@ def test_builtin_module_with_path(Script):
|
||||
assert semlock.name == 'SemLock'
|
||||
assert semlock.line is None
|
||||
assert semlock.column is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'code, description', [
|
||||
('int', 'instance int'),
|
||||
('str.index', 'instance int'),
|
||||
('1', None),
|
||||
]
|
||||
)
|
||||
def test_execute(Script, code, description):
|
||||
definition, = Script(code).goto_assignments()
|
||||
definitions = definition.execute()
|
||||
if description is None:
|
||||
assert not definitions
|
||||
else:
|
||||
d, = definitions
|
||||
assert d.description == description
|
||||
|
||||
Reference in New Issue
Block a user