1
0
forked from VimPlug/jedi

protect more Execution methods

This commit is contained in:
David Halter
2013-12-23 22:58:02 +01:00
parent 8d2b3a0f7c
commit 5b33de991b

View File

@@ -405,7 +405,7 @@ class Execution(Executable):
multiple calls to functions and recursion has to be avoided. But this is multiple calls to functions and recursion has to be avoided. But this is
responsibility of the decorators. responsibility of the decorators.
""" """
def follow_var_arg(self, index): def _follow_var_arg(self, index):
try: try:
stmt = self.var_args[index] stmt = self.var_args[index]
except IndexError: except IndexError:
@@ -438,8 +438,8 @@ class Execution(Executable):
# some implementations of builtins: # some implementations of builtins:
if func_name == 'getattr': if func_name == 'getattr':
# follow the first param # follow the first param
objects = self.follow_var_arg(0) objects = self._follow_var_arg(0)
names = self.follow_var_arg(1) names = self._follow_var_arg(1)
for obj in objects: for obj in objects:
if not isinstance(obj, (Instance, Class, pr.Module)): if not isinstance(obj, (Instance, Class, pr.Module)):
debug.warning('getattr called without instance') debug.warning('getattr called without instance')
@@ -457,7 +457,7 @@ class Execution(Executable):
elif func_name == 'type': elif func_name == 'type':
# otherwise it would be a metaclass # otherwise it would be a metaclass
if len(self.var_args) == 1: if len(self.var_args) == 1:
objects = self.follow_var_arg(0) objects = self._follow_var_arg(0)
return [o.base for o in objects if isinstance(o, Instance)] return [o.base for o in objects if isinstance(o, Instance)]
elif func_name == 'super': elif func_name == 'super':
# TODO make this able to detect multiple inheritance supers # TODO make this able to detect multiple inheritance supers
@@ -501,7 +501,7 @@ class Execution(Executable):
""" A normal Function execution """ """ A normal Function execution """
# Feed the listeners, with the params. # Feed the listeners, with the params.
for listener in func.listeners: for listener in func.listeners:
listener.execute(self.get_params()) listener.execute(self._get_params())
if func.is_generator and not evaluate_generator: if func.is_generator and not evaluate_generator:
return [Generator(func, self.var_args)] return [Generator(func, self.var_args)]
else: else:
@@ -512,7 +512,7 @@ class Execution(Executable):
return stmts return stmts
@cache.memoize_default(default=()) @cache.memoize_default(default=())
def get_params(self): def _get_params(self):
""" """
This returns the params for an Execution/Instance and is injected as a This returns the params for an Execution/Instance and is injected as a
'hack' into the pr.Function class. 'hack' into the pr.Function class.
@@ -566,7 +566,7 @@ class Execution(Executable):
param_dict[str(param.get_name())] = param param_dict[str(param.get_name())] = param
# There may be calls, which don't fit all the params, this just ignores # There may be calls, which don't fit all the params, this just ignores
# it. # it.
var_arg_iterator = self.get_var_args_iterator() var_arg_iterator = self._get_var_args_iterator()
non_matching_keys = [] non_matching_keys = []
keys_used = set() keys_used = set()
@@ -641,7 +641,7 @@ class Execution(Executable):
result.append(gen_param_name_copy(param_dict[k])) result.append(gen_param_name_copy(param_dict[k]))
return result return result
def get_var_args_iterator(self): def _get_var_args_iterator(self):
""" """
Yields a key/value pair, the key is None, if its not a named arg. Yields a key/value pair, the key is None, if its not a named arg.
""" """
@@ -702,12 +702,12 @@ class Execution(Executable):
Call the default method with the own instance (self implements all Call the default method with the own instance (self implements all
the necessary functions). Add also the params. the necessary functions). Add also the params.
""" """
return self.get_params() + pr.Scope.get_set_vars(self) return self._get_params() + pr.Scope.get_set_vars(self)
get_set_vars = get_defined_names get_set_vars = get_defined_names
@common.rethrow_uncaught @common.rethrow_uncaught
def copy_properties(self, prop): def _copy_properties(self, prop):
""" """
Literally copies a property of a Function. Copying is very expensive, Literally copies a property of a Function. Copying is very expensive,
because it is something like `copy.deepcopy`. However, these copied because it is something like `copy.deepcopy`. However, these copied
@@ -751,22 +751,22 @@ class Execution(Executable):
@property @property
@cache.memoize_default() @cache.memoize_default()
def returns(self): def returns(self):
return self.copy_properties('returns') return self._copy_properties('returns')
@property @property
@cache.memoize_default() @cache.memoize_default()
def asserts(self): def asserts(self):
return self.copy_properties('asserts') return self._copy_properties('asserts')
@property @property
@cache.memoize_default() @cache.memoize_default()
def statements(self): def statements(self):
return self.copy_properties('statements') return self._copy_properties('statements')
@property @property
@cache.memoize_default() @cache.memoize_default()
def subscopes(self): def subscopes(self):
return self.copy_properties('subscopes') return self._copy_properties('subscopes')
def get_statement_for_position(self, pos): def get_statement_for_position(self, pos):
return pr.Scope.get_statement_for_position(self, pos) return pr.Scope.get_statement_for_position(self, pos)