diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index 77ed844e..5171448f 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -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): diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index c5906dab..85a1329f 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -388,12 +388,18 @@ 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 - result = _check_isinstance_type(evaluator, ass.assertion(), search_name) - if result: - break + # 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 if isinstance(flow, (pr.IfStmt, pr.WhileStmt)): element = flow.children[1] diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 29816cd4..a3ea1970 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -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)) diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index e1ed6d4a..6a80a5fe 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -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): diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index 52150efd..668bb5bb 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -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 []