From 464968aed785bd88ea512b668f569d335990df14 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 21 Dec 2016 00:23:50 +0100 Subject: [PATCH] Fix an issue where compiled object api types raised an error. --- jedi/evaluate/compiled/__init__.py | 2 +- jedi/parser/fast.py | 15 ++++++++------- test/test_api/test_classes.py | 10 +++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index d4bad6a1..0708edab 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -272,7 +272,7 @@ class CompiledName(AbstractNameDefinition): @property def api_type(self): - return self.infer()[0].api_type + return next(iter(self.infer())).api_type @underscore_memoization def infer(self): diff --git a/jedi/parser/fast.py b/jedi/parser/fast.py index 8ee49491..a8047c28 100644 --- a/jedi/parser/fast.py +++ b/jedi/parser/fast.py @@ -171,7 +171,7 @@ class DiffParser(object): assert operation == 'delete' # Cleanup (setting endmarker, used_names) - self._post_parse() + self._cleanup() if self._added_newline: self._parser.module = self._parser._parsed = self._new_module self._parser.remove_last_newline() @@ -414,11 +414,12 @@ class DiffParser(object): def _get_children_nodes(self, node): nodes = node.children first_element = nodes[0] - if first_element.type == 'error_leaf' and \ - first_element.original_type == 'indent': - assert nodes[-1].type == 'dedent' - # This means that the start and end leaf - nodes = nodes[1:-2] + [nodes[-1]] + # TODO this looks very strange... + #if first_element.type == 'error_leaf' and \ + #first_element.original_type == 'indent': + #assert nodes[-1].type == 'dedent' + ## This means that the start and end leaf + #nodes = nodes[1:-1] + [nodes[-1]] return nodes @@ -440,7 +441,7 @@ class DiffParser(object): ) return self._active_parser.parse(tokenizer=tokenizer) - def _post_parse(self): + def _cleanup(self): # Add the used names from the old parser to the new one. copied_line_numbers = set() for l1, l2 in self._copied_ranges: diff --git a/test/test_api/test_classes.py b/test/test_api/test_classes.py index 170c1951..a4a27eaf 100644 --- a/test/test_api/test_classes.py +++ b/test/test_api/test_classes.py @@ -238,9 +238,13 @@ class TestParent(TestCase): def test_type(): - """ - Github issue #397, type should never raise an error. - """ + for c in Script('a = [str()]; a[0].').completions(): + if c.name == '__class__': + assert c.type == 'class' + else: + assert c.type in ('function', 'instance') + + # Github issue #397, type should never raise an error. for c in Script('import os; os.path.').completions(): assert c.type