forked from VimPlug/jedi
replace propery with safe_property in some evaluate cases. fixes #249
This commit is contained in:
@@ -13,7 +13,6 @@ class MultiLevelStopIteration(Exception):
|
||||
"""
|
||||
StopIteration's get catched pretty easy by for loops, let errors propagate.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class UncaughtAttributeError(Exception):
|
||||
@@ -29,7 +28,11 @@ class UncaughtAttributeError(Exception):
|
||||
"""
|
||||
|
||||
|
||||
def rethrow_uncaught(func):
|
||||
def safe_property(func):
|
||||
return property(reraise_uncaught(func))
|
||||
|
||||
|
||||
def reraise_uncaught(func):
|
||||
"""
|
||||
Re-throw uncaught `AttributeError`.
|
||||
|
||||
|
||||
@@ -219,7 +219,6 @@ class Evaluator(object):
|
||||
result = new_result
|
||||
return set(result)
|
||||
|
||||
@common.rethrow_uncaught
|
||||
def eval_expression_list(self, expression_list, follow_array=False):
|
||||
"""
|
||||
`expression_list` can be either `pr.Array` or `list of list`.
|
||||
|
||||
@@ -125,7 +125,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
names = scope.get_defined_names()
|
||||
return [ArrayMethod(n) for n in names]
|
||||
|
||||
@property
|
||||
@common.safe_property
|
||||
def parent(self):
|
||||
return compiled.builtin
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class Executable(pr.IsScope):
|
||||
def get_parent_until(self, *args, **kwargs):
|
||||
return self.base.get_parent_until(*args, **kwargs)
|
||||
|
||||
@property
|
||||
@common.safe_property
|
||||
def parent(self):
|
||||
return self.base.parent
|
||||
|
||||
@@ -193,7 +193,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
self.var = var
|
||||
self.is_class_var = is_class_var
|
||||
|
||||
@property
|
||||
@common.safe_property
|
||||
@memoize_default(None)
|
||||
def parent(self):
|
||||
par = self.var.parent
|
||||
@@ -297,7 +297,7 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
|
||||
return sub
|
||||
raise KeyError("Couldn't find subscope.")
|
||||
|
||||
@property
|
||||
@common.safe_property
|
||||
def name(self):
|
||||
return self.base.name
|
||||
|
||||
@@ -434,7 +434,6 @@ class FunctionExecution(Executable):
|
||||
|
||||
get_set_vars = get_defined_names
|
||||
|
||||
@common.rethrow_uncaught
|
||||
def _copy_properties(self, prop):
|
||||
"""
|
||||
Literally copies a property of a Function. Copying is very expensive,
|
||||
@@ -462,7 +461,6 @@ class FunctionExecution(Executable):
|
||||
return getattr(self.base, name)
|
||||
|
||||
@memoize_default(None)
|
||||
@common.rethrow_uncaught
|
||||
def _scope_copy(self, scope):
|
||||
""" Copies a scope (e.g. if) in an execution """
|
||||
# TODO method uses different scopes than the subscopes property.
|
||||
@@ -476,22 +474,22 @@ class FunctionExecution(Executable):
|
||||
copied.parent = self._scope_copy(copied.parent)
|
||||
return copied
|
||||
|
||||
@property
|
||||
@common.safe_property
|
||||
@memoize_default([])
|
||||
def returns(self):
|
||||
return self._copy_properties('returns')
|
||||
|
||||
@property
|
||||
@common.safe_property
|
||||
@memoize_default([])
|
||||
def asserts(self):
|
||||
return self._copy_properties('asserts')
|
||||
|
||||
@property
|
||||
@common.safe_property
|
||||
@memoize_default([])
|
||||
def statements(self):
|
||||
return self._copy_properties('statements')
|
||||
|
||||
@property
|
||||
@common.safe_property
|
||||
@memoize_default([])
|
||||
def subscopes(self):
|
||||
return self._copy_properties('subscopes')
|
||||
|
||||
Reference in New Issue
Block a user