1
0
forked from VimPlug/jedi

added a scope generator for instances, which is necessary, because instance variables have priority over class vars

This commit is contained in:
David Halter
2012-09-04 15:25:08 +02:00
parent 3cc5c60f02
commit db7c2fc6e7
2 changed files with 29 additions and 10 deletions

View File

@@ -243,6 +243,19 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
names.append(InstanceElement(self, var, True)) names.append(InstanceElement(self, var, True))
return names return names
def scope_generator(self):
"""
An Instance has two scopes: The scope with self names and the class
scope. Instance variables have priority over the class scope.
"""
yield self, self.get_self_properties()
names = []
class_names = self.base.get_defined_names()
for var in class_names:
names.append(InstanceElement(self, var, True))
yield self, names
def get_index_types(self, index=None): def get_index_types(self, index=None):
args = helpers.generate_param_array([] if index is None else [index]) args = helpers.generate_param_array([] if index is None else [index])
try: try:
@@ -890,8 +903,12 @@ def get_names_for_scope(scope, position=None, star_search=True,
and non_flow.isinstance(Function) and non_flow.isinstance(Function)
): ):
try: try:
yield scope, get_defined_names_for_position(scope, position, if isinstance(scope, Instance):
in_func_scope) for g in scope.scope_generator():
yield g
else:
yield scope, get_defined_names_for_position(scope,
position, in_func_scope)
except StopIteration: except StopIteration:
raise MultiLevelStopIteration('StopIteration raised somewhere') raise MultiLevelStopIteration('StopIteration raised somewhere')
if scope.isinstance(parsing.ForFlow) and scope.is_list_comp: if scope.isinstance(parsing.ForFlow) and scope.is_list_comp:
@@ -1059,9 +1076,8 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
no_break_scope = True no_break_scope = True
# TODO this makes self variables non-breakable. wanted? # TODO this makes self variables non-breakable. wanted?
#r = [n for n in par.get_set_vars() if isinstance(name, InstanceElement) \
# if len(n) > 1 and str(n.names[-1] == name)] and not name.is_class_var:
if isinstance(name, InstanceElement):# and r:
no_break_scope = True no_break_scope = True
result.append(par) result.append(par)
@@ -1115,8 +1131,11 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
if search_global: if search_global:
scope_generator = get_names_for_scope(scope, position=position) scope_generator = get_names_for_scope(scope, position=position)
else: else:
names = get_defined_names_for_position(scope, position) if isinstance(scope, Instance):
scope_generator = iter([(scope, names)]) scope_generator = scope.scope_generator()
else:
names = get_defined_names_for_position(scope, position)
scope_generator = iter([(scope, names)])
return descriptor_check(remove_statements(filter_name(scope_generator))) return descriptor_check(remove_statements(filter_name(scope_generator)))

View File

@@ -101,14 +101,14 @@ class A(object):
self.b = list self.b = list
self.a = 1 self.a = 1
#? list() str() int() #? str() int()
self.a self.a
#? ['after'] #? ['after']
self.after self.after
self.c = 3 self.c = 3
#? set() int() #? int()
self.c self.c
def after(self): def after(self):
@@ -129,7 +129,7 @@ a.append
#? [] #? []
a.real a.real
#? list() str() int() #? str() int()
a.a a.a
a = 3 a = 3