def _validate_import(self, module_line, lineno): """Try to validate the given iport line """ if 'noqa' in module_line: return True error = [] error_string = 'can\'t import {0}' valid = True for word in module_line.split(): if word in ('from', 'import', 'as'): continue offset = int(module_line.find(word) + len(word) / 2) s = Script(self.source, lineno, offset, self.filename) if not self.filename: s = Script(module_line, 1, offset) if not s.goto_assignments(): if valid is True: valid = False error.append(word) err = '' if valid else error_string.format(' '.join(error)) return err, valid
def _validate_import(self, module_line, lineno): """Try to validate the given iport line """ if 'noqa' in module_line: return True jedi_project = get_default_project(self.filename) if self.settings.get("python_interpreter", "") != "": jedi_project._environment_path = self.settings.get( "python_interpreter") error = [] error_string = 'can\'t import {0}' valid = True for word in module_line.split(): if word in ('from', 'import', 'as'): continue offset = int(module_line.find(word) + len(word) / 2) s = Script(self.source, lineno, offset, self.filename, project=jedi_project) if not self.filename: s = Script(module_line, 1, offset, project=jedi_project) if not s.goto_assignments(): if valid is True: valid = False error.append(word) err = '' if valid else error_string.format(' '.join(error)) return err, valid
def make_definitions(): """ Return a list of definitions for parametrized tests. :rtype: [jedi.api_classes.BaseDefinition] """ source = dedent( """ import sys class C: pass x = C() def f(): pass def g(): yield h = lambda: None """ ) definitions = [] definitions += defined_names(source) source += dedent( """ variable = sys or C or x or f or g or g() or h""" ) lines = source.splitlines() script = Script(source, len(lines), len("variable"), None) definitions += script.goto_definitions() script2 = Script(source, 4, len("class C"), None) definitions += script2.usages() source_param = "def f(a): return a" script_param = Script(source_param, 1, len(source_param), None) definitions += script_param.goto_assignments() return definitions
def make_definitions(): """ Return a list of definitions for parametrized tests. :rtype: [jedi.api_classes.BaseDefinition] """ source = dedent(""" import sys class C: pass x = C() def f(): pass def g(): yield h = lambda: None """) definitions = [] definitions += defined_names(source) source += dedent(""" variable = sys or C or x or f or g or g() or h""") lines = source.splitlines() script = Script(source, len(lines), len('variable'), None) definitions += script.goto_definitions() script2 = Script(source, 4, len('class C'), None) definitions += script2.usages() source_param = "def f(a): return a" script_param = Script(source_param, 1, len(source_param), None) definitions += script_param.goto_assignments() return definitions