forked from VimPlug/jedi
Remove asserts and calculate them dynamically.
This commit is contained in:
@@ -39,7 +39,6 @@ class CheckAttribute(object):
|
|||||||
class CompiledObject(Base):
|
class CompiledObject(Base):
|
||||||
# comply with the parser
|
# comply with the parser
|
||||||
start_pos = 0, 0
|
start_pos = 0, 0
|
||||||
asserts = []
|
|
||||||
path = None # modules have this attribute - set it to None.
|
path = None # modules have this attribute - set it to None.
|
||||||
|
|
||||||
def __init__(self, obj, parent=None):
|
def __init__(self, obj, parent=None):
|
||||||
|
|||||||
@@ -388,12 +388,18 @@ def check_flow_information(evaluator, flow, search_name, pos):
|
|||||||
|
|
||||||
result = []
|
result = []
|
||||||
if flow.is_scope():
|
if flow.is_scope():
|
||||||
for ass in reversed(flow.asserts):
|
# Check for asserts.
|
||||||
if pos is None or ass.start_pos > pos:
|
try:
|
||||||
continue
|
names = reversed(flow.names_dict[search_name.value])
|
||||||
result = _check_isinstance_type(evaluator, ass.assertion(), search_name)
|
except (KeyError, AttributeError):
|
||||||
if result:
|
names = []
|
||||||
break
|
|
||||||
|
for name in names:
|
||||||
|
ass = name.get_parent_until(pr.AssertStmt)
|
||||||
|
if isinstance(ass, pr.AssertStmt) and pos is not None and ass.start_pos < pos:
|
||||||
|
result = _check_isinstance_type(evaluator, ass.assertion(), search_name)
|
||||||
|
if result:
|
||||||
|
break
|
||||||
|
|
||||||
if isinstance(flow, (pr.IfStmt, pr.WhileStmt)):
|
if isinstance(flow, (pr.IfStmt, pr.WhileStmt)):
|
||||||
element = flow.children[1]
|
element = flow.children[1]
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin))
|
|||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name not in ['start_pos', 'end_pos', 'parent', 'get_imports',
|
if name not in ['start_pos', 'end_pos', 'parent', 'get_imports',
|
||||||
'asserts', 'doc', 'docstr', 'get_parent_until',
|
'doc', 'docstr', 'get_parent_until',
|
||||||
'get_code', 'subscopes']:
|
'get_code', 'subscopes']:
|
||||||
raise AttributeError("Accessing %s of %s is not allowed."
|
raise AttributeError("Accessing %s of %s is not allowed."
|
||||||
% (self, name))
|
% (self, name))
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
|||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name not in ['start_pos', 'end_pos', 'get_imports', 'type',
|
if name not in ['start_pos', 'end_pos', 'get_imports', 'type',
|
||||||
'doc', 'raw_doc', 'asserts']:
|
'doc', 'raw_doc']:
|
||||||
raise AttributeError("Instance %s: Don't touch this (%s)!"
|
raise AttributeError("Instance %s: Don't touch this (%s)!"
|
||||||
% (self, name))
|
% (self, name))
|
||||||
return getattr(self.base, name)
|
return getattr(self.base, name)
|
||||||
@@ -449,7 +449,7 @@ class Class(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
raise KeyError("Couldn't find subscope.")
|
raise KeyError("Couldn't find subscope.")
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name not in ['start_pos', 'end_pos', 'parent', 'asserts', 'raw_doc',
|
if name not in ['start_pos', 'end_pos', 'parent', 'raw_doc',
|
||||||
'doc', 'get_imports', 'get_parent_until', 'get_code',
|
'doc', 'get_imports', 'get_parent_until', 'get_code',
|
||||||
'subscopes', 'names_dict', 'type']:
|
'subscopes', 'names_dict', 'type']:
|
||||||
raise AttributeError("Don't touch this: %s of %s !" % (name, self))
|
raise AttributeError("Don't touch this: %s of %s !" % (name, self))
|
||||||
@@ -667,11 +667,6 @@ class FunctionExecution(Executed):
|
|||||||
def yields(self):
|
def yields(self):
|
||||||
return self._copy_list(self.base.yields)
|
return self._copy_list(self.base.yields)
|
||||||
|
|
||||||
@common.safe_property
|
|
||||||
@memoize_default([])
|
|
||||||
def asserts(self):
|
|
||||||
return self._copy_list(self.base.asserts)
|
|
||||||
|
|
||||||
@common.safe_property
|
@common.safe_property
|
||||||
@memoize_default([])
|
@memoize_default([])
|
||||||
def statements(self):
|
def statements(self):
|
||||||
|
|||||||
@@ -526,12 +526,6 @@ class Scope(BaseNode, DocstringMixin):
|
|||||||
# returns will be in "normal" modules.
|
# returns will be in "normal" modules.
|
||||||
return self._search_in_scope(ReturnStmt)
|
return self._search_in_scope(ReturnStmt)
|
||||||
|
|
||||||
@property
|
|
||||||
def asserts(self):
|
|
||||||
# Needed here for fast_parser, because the fast_parser splits and
|
|
||||||
# returns will be in "normal" modules.
|
|
||||||
return self._search_in_scope(AssertStmt)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subscopes(self):
|
def subscopes(self):
|
||||||
return self._search_in_scope(Scope)
|
return self._search_in_scope(Scope)
|
||||||
@@ -1203,8 +1197,3 @@ class CompFor(BaseNode):
|
|||||||
|
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
return _defined_names(self.children[1])
|
return _defined_names(self.children[1])
|
||||||
|
|
||||||
@property
|
|
||||||
def asserts(self):
|
|
||||||
"""Since it's a scope, it can be asked for asserts."""
|
|
||||||
return []
|
|
||||||
|
|||||||
Reference in New Issue
Block a user