forked from VimPlug/jedi
Fix issues with generators.
This commit is contained in:
@@ -112,6 +112,12 @@ class NameFinder(object):
|
||||
last_names.append(name)
|
||||
continue
|
||||
|
||||
if isinstance(name_scope, compiled.CompiledObject):
|
||||
# Let's test this. TODO need comment. shouldn't this be
|
||||
# filtered before?
|
||||
last_names.append(name)
|
||||
continue
|
||||
|
||||
if isinstance(name, compiled.CompiledName) \
|
||||
or isinstance(name, er.InstanceName) and isinstance(name._origin_name, compiled.CompiledName):
|
||||
last_names.append(name)
|
||||
@@ -516,7 +522,8 @@ def global_names_dict_generator(evaluator, scope, position):
|
||||
"""
|
||||
in_func = False
|
||||
while scope is not None:
|
||||
if not (scope.type == 'classdef' and in_func):
|
||||
if not((scope.type == 'classdef' or isinstance(scope,
|
||||
compiled.CompiledObject) and scope.type() == 'class') and in_func):
|
||||
# Names in methods cannot be resolved within the class.
|
||||
|
||||
for names_dict in scope.names_dicts():
|
||||
|
||||
@@ -185,13 +185,24 @@ class FakeImport(pr.Import):
|
||||
|
||||
|
||||
class FakeName(pr.Name):
|
||||
def __init__(self, name_str, parent=None, start_pos=(0, 0)):
|
||||
def __init__(self, name_str, parent=None, start_pos=(0, 0), is_definition=None):
|
||||
"""
|
||||
In case is_definition is defined (not None), that bool value will be
|
||||
returned.
|
||||
"""
|
||||
super(FakeName, self).__init__(name_str, start_pos)
|
||||
self.parent = parent
|
||||
self._is_definition = is_definition
|
||||
|
||||
def get_definition(self):
|
||||
return self.parent
|
||||
|
||||
def is_definition(self):
|
||||
if self._is_definition is None:
|
||||
return super(FakeName, self).is_definition()
|
||||
else:
|
||||
return self._is_definition
|
||||
|
||||
|
||||
class LazyName(FakeName):
|
||||
def __init__(self, name, parent_callback):
|
||||
|
||||
@@ -62,6 +62,18 @@ class GeneratorMixin(object):
|
||||
def scope_names_generator(self, position=None):
|
||||
yield self, self._get_defined_names()
|
||||
|
||||
@underscore_memoization
|
||||
def names_dicts(self):
|
||||
dct = {}
|
||||
executes_generator = '__next__', 'send', 'next'
|
||||
for name in compiled.generator_obj.get_defined_names():
|
||||
if name.value in executes_generator:
|
||||
parent = GeneratorMethod(self, name.parent)
|
||||
dct[name.value] = [helpers.FakeName(name.name, parent, is_definition=True)]
|
||||
else:
|
||||
dct[name.value] = [name]
|
||||
yield dct
|
||||
|
||||
def get_index_types(self, evaluator, index_array):
|
||||
#debug.warning('Tried to get array access on a generator: %s', self)
|
||||
analysis.add(self._evaluator, 'type-error-generator', index_array)
|
||||
|
||||
Reference in New Issue
Block a user