diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 7c9637f4..37d65c18 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -621,7 +621,10 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)): d = d.parent if isinstance(d, compiled.CompiledObject): - d = d.type() + ' ' + d.name + typ = d.type() + if typ == 'instance': + typ = 'class' # The description should be similar to Py objects. + d = typ + ' ' + d.name elif isinstance(d, iterable.Array): d = 'class ' + d.type elif isinstance(d, (pr.Class, er.Class, er.Instance)): diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index 7e43298a..b3be0bc4 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -77,6 +77,9 @@ class CompiledObject(Base): return _parse_function_doc(self.doc) def type(self): + if fake.is_class_instance(self.obj): + return 'instance' + cls = self._cls().obj if inspect.isclass(cls): return 'class' diff --git a/test/completion/functions.py b/test/completion/functions.py index 86b36c58..be3b5853 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -21,7 +21,7 @@ arr def inputs(param): return param -#? list() +#? list inputs(list) def variable_middle(): diff --git a/test/run.py b/test/run.py index e1e2b132..82a48fdc 100755 --- a/test/run.py +++ b/test/run.py @@ -170,6 +170,10 @@ class IntegrationTestCase(object): return compare_cb(self, comp_str, set(literal_eval(self.correct))) def run_goto_definitions(self, compare_cb): + def comparison(definition): + suffix = '()' if definition.type == 'instance' else '' + return definition.desc_with_module + suffix + def definition(correct, correct_start, path): def defs(line_nr, indent): s = jedi.Script(self.source, line_nr, indent, path) @@ -177,30 +181,29 @@ class IntegrationTestCase(object): should_be = set() number = 0 - for index in re.finditer('(?: +|$)', correct): - if correct == ' ': - continue - # -1 for the comment, +3 because of the comment start `#? ` - start = index.start() + for index in re.finditer('(?:[^ ]+)', correct): + end = index.end() + # +3 because of the comment start `#? ` + end += 3 number += 1 try: - should_be |= defs(self.line_nr - 1, start + correct_start) + should_be |= defs(self.line_nr - 1, end + correct_start) except Exception: print('could not resolve %s indent %s' - % (self.line_nr - 1, start)) + % (self.line_nr - 1, end)) raise # because the objects have different ids, `repr`, then compare. - should_str = set(r.desc_with_module for r in should_be) - if len(should_str) < number: - raise Exception('Solution @%s not right, ' - 'too few test results: %s' % (self.line_nr - 1, should_str)) - return should_str + should = set(comparison(r) for r in should_be) + if len(should) < number: + raise Exception('Solution @%s not right, too few test results: %s' + % (self.line_nr - 1, should)) + return should script = self.script() - should_str = definition(self.correct, self.start, script.path) + should = definition(self.correct, self.start, script.path) result = script.goto_definitions() - is_str = set(r.desc_with_module for r in result) - return compare_cb(self, is_str, should_str) + is_str = set(comparison(r) for r in result) + return compare_cb(self, is_str, should) def run_goto_assignments(self, compare_cb): result = self.script().goto_assignments() @@ -390,8 +393,8 @@ if __name__ == '__main__': file_change(current, count, fails) - print('\nSummary: (%s fails of %s tests) in %.3fs' % (tests_fail, - len(cases), time.time() - t_start)) + print('\nSummary: (%s fails of %s tests) in %.3fs' + % (tests_fail, len(cases), time.time() - t_start)) for s in summary: print(s)