def test_completion_param_annotations(): # Need to define this function not directly in Python. Otherwise Jedi is to # clever and uses the Python code instead of the signature object. code = 'def foo(a: 1, b: str, c: int = 1.0): pass' exec_function(code, locals()) script = jedi.Interpreter('foo', [locals()]) c, = script.completions() a, b, c = c.params assert a._goto_definitions() == [] assert [d.name for d in b._goto_definitions()] == ['str'] assert set([d.name for d in c._goto_definitions()]) == set(['int', 'float'])
def _execute_code(module_path, code): c = "import os; from os.path import *; result=%s" variables = {'__file__': module_path} try: exec_function(c % code, variables) except Exception: debug.warning('sys.path manipulation detected, but failed to evaluate.') else: try: res = variables['result'] if isinstance(res, str): return [os.path.abspath(res)] except KeyError: pass return []
def execute_code(code): c = "import os; from os.path import *; result=%s" variables = {'__file__': module.path} try: exec_function(c % code, variables) except Exception: debug.warning('sys path detected, but failed to evaluate') return None try: res = variables['result'] if isinstance(res, str): return os.path.abspath(res) else: return None except KeyError: return None
def load_module(name, path): if path: self.sys_path.insert(0, path) temp, sys.path = sys.path, self.sys_path content = {} try: exec_function('import %s as module' % name, content) self._module = content['module'] except AttributeError: # use sys.modules, because you cannot access some modules # directly. -> #59 self._module = sys.modules[name] sys.path = temp if path: self.sys_path.pop(0)