1
0
forked from VimPlug/jedi

Remove asserts and calculate them dynamically.

This commit is contained in:
Dave Halter
2015-02-05 20:16:55 +01:00
parent 0a3797cf6e
commit 8125d5f562
5 changed files with 15 additions and 26 deletions

View File

@@ -39,7 +39,6 @@ class CheckAttribute(object):
class CompiledObject(Base):
# comply with the parser
start_pos = 0, 0
asserts = []
path = None # modules have this attribute - set it to None.
def __init__(self, obj, parent=None):

View File

@@ -388,9 +388,15 @@ def check_flow_information(evaluator, flow, search_name, pos):
result = []
if flow.is_scope():
for ass in reversed(flow.asserts):
if pos is None or ass.start_pos > pos:
continue
# Check for asserts.
try:
names = reversed(flow.names_dict[search_name.value])
except (KeyError, AttributeError):
names = []
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

View File

@@ -88,7 +88,7 @@ class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin))
def __getattr__(self, name):
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']:
raise AttributeError("Accessing %s of %s is not allowed."
% (self, name))

View File

@@ -231,7 +231,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
def __getattr__(self, name):
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)!"
% (self, name))
return getattr(self.base, name)
@@ -449,7 +449,7 @@ class Class(use_metaclass(CachedMetaClass, Wrapper)):
raise KeyError("Couldn't find subscope.")
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',
'subscopes', 'names_dict', 'type']:
raise AttributeError("Don't touch this: %s of %s !" % (name, self))
@@ -667,11 +667,6 @@ class FunctionExecution(Executed):
def yields(self):
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
@memoize_default([])
def statements(self):

View File

@@ -526,12 +526,6 @@ class Scope(BaseNode, DocstringMixin):
# returns will be in "normal" modules.
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
def subscopes(self):
return self._search_in_scope(Scope)
@@ -1203,8 +1197,3 @@ class CompFor(BaseNode):
def get_defined_names(self):
return _defined_names(self.children[1])
@property
def asserts(self):
"""Since it's a scope, it can be asked for asserts."""
return []