1
0
forked from VimPlug/jedi

Use @common.rethrow_uncaught and stop manual re-raise

This commit is contained in:
Takafumi Arakaki
2013-03-13 23:21:49 +01:00
parent e42ff9e762
commit eca0f01cfb
2 changed files with 27 additions and 36 deletions

View File

@@ -581,12 +581,7 @@ def follow_statement(stmt, seek_name=None):
commands = stmt.get_commands() commands = stmt.get_commands()
debug.dbg('calls: %s' % commands) debug.dbg('calls: %s' % commands)
try: result = follow_call_list(commands)
result = follow_call_list(commands)
except AttributeError:
# This is so evil! But necessary to propagate errors. The attribute
# errors here must not be catched, because they shouldn't exist.
raise common.MultiLevelAttributeError(sys.exc_info())
# Assignment checking is only important if the statement defines multiple # Assignment checking is only important if the statement defines multiple
# variables. # variables.
@@ -598,6 +593,7 @@ def follow_statement(stmt, seek_name=None):
return set(result) return set(result)
@common.rethrow_uncaught
def follow_call_list(call_list, follow_array=False): def follow_call_list(call_list, follow_array=False):
""" """
`call_list` can be either `pr.Array` or `list of list`. `call_list` can be either `pr.Array` or `list of list`.

View File

@@ -9,7 +9,6 @@ instantiated. This class represents these cases.
So, why is there also a ``Class`` class here? Well, there are decorators and So, why is there also a ``Class`` class here? Well, there are decorators and
they change classes in Python 3. they change classes in Python 3.
""" """
import sys
import copy import copy
import itertools import itertools
@@ -668,6 +667,7 @@ class Execution(Executable):
""" """
return self.get_params() + pr.Scope.get_set_vars(self) return self.get_params() + pr.Scope.get_set_vars(self)
@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,
@@ -675,22 +675,19 @@ class Execution(Executable):
objects can be used for the executions, as if they were in the objects can be used for the executions, as if they were in the
execution. execution.
""" """
try: # Copy all these lists into this local function.
# Copy all these lists into this local function. attr = getattr(self.base, prop)
attr = getattr(self.base, prop) objects = []
objects = [] for element in attr:
for element in attr: if element is None:
if element is None: copied = element
copied = element else:
else: copied = helpers.fast_parent_copy(element)
copied = helpers.fast_parent_copy(element) copied.parent = self._scope_copy(copied.parent)
copied.parent = self._scope_copy(copied.parent) if isinstance(copied, pr.Function):
if isinstance(copied, pr.Function): copied = Function(copied)
copied = Function(copied) objects.append(copied)
objects.append(copied) return objects
return objects
except AttributeError:
raise common.MultiLevelAttributeError(sys.exc_info())
def __getattr__(self, name): def __getattr__(self, name):
if name not in ['start_pos', 'end_pos', 'imports', '_sub_module']: if name not in ['start_pos', 'end_pos', 'imports', '_sub_module']:
@@ -698,21 +695,19 @@ class Execution(Executable):
return getattr(self.base, name) return getattr(self.base, name)
@cache.memoize_default() @cache.memoize_default()
@common.rethrow_uncaught
def _scope_copy(self, scope): def _scope_copy(self, scope):
try: """ Copies a scope (e.g. if) in an execution """
""" Copies a scope (e.g. if) in an execution """ # TODO method uses different scopes than the subscopes property.
# TODO method uses different scopes than the subscopes property.
# just check the start_pos, sometimes it's difficult with closures # just check the start_pos, sometimes it's difficult with closures
# to compare the scopes directly. # to compare the scopes directly.
if scope.start_pos == self.start_pos: if scope.start_pos == self.start_pos:
return self return self
else: else:
copied = helpers.fast_parent_copy(scope) copied = helpers.fast_parent_copy(scope)
copied.parent = self._scope_copy(copied.parent) copied.parent = self._scope_copy(copied.parent)
return copied return copied
except AttributeError:
raise common.MultiLevelAttributeError(sys.exc_info())
@property @property
@cache.memoize_default() @cache.memoize_default()