def actual(evaluator, params): # Parse the docstring to find the return type: ret_type = '' if '->' in self.obj.__doc__: ret_type = self.obj.__doc__.split('->')[1].strip() ret_type = ret_type.replace(' or None', '') if ret_type.startswith('iter:'): ret_type = ret_type[len('iter:'):] # we don't care if it's an iterator if ret_type in __builtins__: # The function we're inspecting returns a builtin python type, that's easy obj = _create_from_name(builtin, builtin, ret_type) return evaluator.execute(obj, params) else: # The function we're inspecting returns a GObject type parent = self.parent.obj.__name__ if parent.startswith('gi.repository'): parent = parent[len('gi.repository.'):] else: # a module with overrides, such as Gtk, behaves differently parent_module = self.parent.obj.__module__ if parent_module.startswith('gi.overrides'): parent_module = parent_module[len('gi.overrides.'):] parent = '%s.%s' % (parent_module, parent) if ret_type.startswith(parent): # A pygobject type in the same module ret_type = ret_type[len(parent):] else: # A pygobject type in a different module return_type_parent = ret_type.split('.', 1)[0] ret_type = 'from gi.repository import %s\n%s' % (return_type_parent, ret_type) result = _evaluate_for_statement_string(evaluator, ret_type, self.parent) return result
def test_fake_loading(): assert isinstance(compiled.create(Evaluator(), next), Function) string = compiled.builtin.get_subscope_by_name('str') from_name = compiled._create_from_name(compiled.builtin, string, '__init__') assert isinstance(from_name, Function)
def test_fake_loading(): e = _evaluator() assert isinstance(compiled.create(e, next), FunctionContext) builtin = compiled.get_special_object(e, 'BUILTINS') string, = builtin.py__getattribute__('str') from_name = compiled._create_from_name(e, builtin, string, '__init__') assert isinstance(from_name, FunctionContext)
def test_fake_loading(): e = _evaluator() assert isinstance(compiled.create(e, next), Function) builtin = compiled.get_special_object(e, 'BUILTINS') string = builtin.get_subscope_by_name('str') from_name = compiled._create_from_name(e, builtin, string, '__init__') assert isinstance(from_name, Function)
def test_fake_loading(): assert isinstance(compiled.create(Evaluator(load_grammar()), next), Function) string = compiled.builtin.get_subscope_by_name('str') from_name = compiled._create_from_name( compiled.builtin, string, '__init__' ) assert isinstance(from_name, Function)
def actual(params): # Parse the docstring to find the return type: ret_type = '' if '->' in self.obj.__doc__: ret_type = self.obj.__doc__.split('->')[1].strip() ret_type = ret_type.replace(' or None', '') if ret_type.startswith('iter:'): ret_type = ret_type[len( 'iter:'):] # we don't care if it's an iterator if hasattr(__builtins__, ret_type): # The function we're inspecting returns a builtin python type, that's easy # (see test/test_evaluate/test_compiled.py in the jedi source code for usage) builtins = get_special_object(self.evaluator, 'BUILTINS') builtin_obj = builtins.py__getattribute__(ret_type) obj = _create_from_name(self.evaluator, builtins, builtin_obj, "") return self.evaluator.execute(obj, params) else: # The function we're inspecting returns a GObject type parent = self.parent_context.obj.__name__ if parent.startswith('gi.repository'): parent = parent[len('gi.repository.'):] else: # a module with overrides, such as Gtk, behaves differently parent_module = self.parent_context.obj.__module__ if parent_module.startswith('gi.overrides'): parent_module = parent_module[len('gi.overrides.' ):] parent = '%s.%s' % (parent_module, parent) if ret_type.startswith(parent): # A pygobject type in the same module ret_type = ret_type[len(parent):] else: # A pygobject type in a different module return_type_parent = ret_type.split('.', 1)[0] ret_type = 'from gi.repository import %s\n%s' % ( return_type_parent, ret_type) result = _evaluate_for_statement_string( self.parent_context, ret_type) return set(result)
def _execute_function(self, evaluator, params): if self.type != 'funcdef': return # patching docstrings here from spyder.utils.introspection import docstrings types = docstrings.find_return_types(evaluator, self) if types: for result in types: debug.dbg('docstrings type return: %s in %s', result, self) yield result # end patch for name in self._parse_function_doc()[1].split(): try: bltn_obj = _create_from_name(builtin, builtin, name) except AttributeError: continue else: if isinstance(bltn_obj, CompiledObject) and bltn_obj.obj is None: # We want everything except None. continue for result in evaluator.execute(bltn_obj, params): yield result
def _execute_function(self, evaluator, params): if self.type != 'funcdef': return # patching docstrings here from spyder.utils.introspection import numpy_docstr types = numpy_docstr.find_return_types(evaluator, self) if types: for result in types: debug.dbg('docstrings type return: %s in %s', result, self) yield result # end patch for name in self._parse_function_doc()[1].split(): try: bltn_obj = _create_from_name(builtin, builtin, name) except AttributeError: continue else: if (isinstance(bltn_obj, CompiledObject) and bltn_obj.obj is None): # We want everything except None. continue for result in evaluator.execute(bltn_obj, params): yield result
def actual(params): # Parse the docstring to find the return type: ret_type = '' if '->' in self.obj.__doc__: ret_type = self.obj.__doc__.split('->')[1].strip() ret_type = ret_type.replace(' or None', '') if ret_type.startswith('iter:'): ret_type = ret_type[len('iter:'):] # we don't care if it's an iterator if hasattr(__builtins__, ret_type): # The function we're inspecting returns a builtin python type, that's easy # (see test/test_evaluate/test_compiled.py in the jedi source code for usage) builtins = get_special_object(self.evaluator, 'BUILTINS') builtin_obj = builtins.py__getattribute__(ret_type) obj = _create_from_name(self.evaluator, builtins, builtin_obj, "") return self.evaluator.execute(obj, params) else: # The function we're inspecting returns a GObject type parent = self.parent_context.obj.__name__ if parent.startswith('gi.repository'): parent = parent[len('gi.repository.'):] else: # a module with overrides, such as Gtk, behaves differently parent_module = self.parent_context.obj.__module__ if parent_module.startswith('gi.overrides'): parent_module = parent_module[len('gi.overrides.'):] parent = '%s.%s' % (parent_module, parent) if ret_type.startswith(parent): # A pygobject type in the same module ret_type = ret_type[len(parent):] else: # A pygobject type in a different module return_type_parent = ret_type.split('.', 1)[0] ret_type = 'from gi.repository import %s\n%s' % (return_type_parent, ret_type) result = _evaluate_for_statement_string(self.parent_context, ret_type) return set(result)