Fix an issue where compiled object api types raised an error.

This commit is contained in:
Dave Halter
2016-12-21 00:23:50 +01:00
parent 90b76ee3ec
commit 464968aed7
3 changed files with 16 additions and 11 deletions

View File

@@ -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):

View File

@@ -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:

View File

@@ -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