forked from VimPlug/jedi
Remove IsScope in favor of an is_scope function.
This function was partially implemented anway. Now we've also added a function called 'get_parent_scope', to make it easy to get a scope of a Call, Statement, whatever.
This commit is contained in:
@@ -220,9 +220,10 @@ class Evaluator(object):
|
||||
"""Follow a call is following a function, variable, string, etc."""
|
||||
path = call.generate_call_path()
|
||||
|
||||
# TODO use scope_parent
|
||||
# find the statement of the Scope
|
||||
s = call
|
||||
while not s.parent.isinstance(pr.IsScope):
|
||||
while not s.parent.is_scope():
|
||||
s = s.parent
|
||||
par = s.parent
|
||||
return self.eval_call_path(path, par, s.start_pos)
|
||||
@@ -335,7 +336,7 @@ class Evaluator(object):
|
||||
return types
|
||||
|
||||
def goto(self, stmt, call_path):
|
||||
scope = stmt.get_parent_until(pr.IsScope)
|
||||
scope = stmt.get_parent_scope()
|
||||
pos = stmt.start_pos
|
||||
call_path, search_name_part = call_path[:-1], call_path[-1]
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from jedi._compatibility import builtins as _builtins, unicode
|
||||
from jedi import debug
|
||||
from jedi.cache import underscore_memoization, memoize
|
||||
from jedi.evaluate.sys_path import get_sys_path
|
||||
from jedi.parser.representation import Param, SubModule, Base, IsScope, Operator
|
||||
from jedi.parser.representation import Param, SubModule, Base, Operator
|
||||
from jedi.evaluate.helpers import FakeName
|
||||
from . import fake
|
||||
|
||||
@@ -374,12 +374,15 @@ def _parse_function_doc(doc):
|
||||
return param_str, ret
|
||||
|
||||
|
||||
class Builtin(CompiledObject, IsScope):
|
||||
class Builtin(CompiledObject, Base):
|
||||
@memoize
|
||||
def get_by_name(self, name):
|
||||
item = [n for n in self.get_defined_names() if n.get_code() == name][0]
|
||||
return item.parent
|
||||
|
||||
def is_scope(self):
|
||||
return True
|
||||
|
||||
|
||||
def _a_generator(foo):
|
||||
"""Used to have an object to return for generators."""
|
||||
|
||||
@@ -380,7 +380,7 @@ def check_flow_information(evaluator, flow, search_name_part, pos):
|
||||
return None
|
||||
|
||||
result = []
|
||||
if isinstance(flow, pr.IsScope):
|
||||
if flow.is_scope():
|
||||
for ass in reversed(flow.asserts):
|
||||
if pos is None or ass.start_pos > pos:
|
||||
continue
|
||||
|
||||
@@ -337,7 +337,7 @@ def _check_array_additions(evaluator, compare_array, module, is_list):
|
||||
backtrack_path = iter(call_path[:separate_index])
|
||||
|
||||
position = c.start_pos
|
||||
scope = c.get_parent_until(pr.IsScope)
|
||||
scope = c.get_parent_scope()
|
||||
|
||||
found = evaluator.eval_call_path(backtrack_path, scope, position)
|
||||
if not compare_array in found:
|
||||
|
||||
@@ -41,7 +41,7 @@ def wrap(evaluator, element):
|
||||
return element
|
||||
|
||||
|
||||
class Executed(pr.IsScope):
|
||||
class Executed(pr.Base):
|
||||
"""
|
||||
An instance is also an executable - because __init__ is called
|
||||
:param var_args: The param input array, consist of `pr.Array` or list.
|
||||
@@ -51,6 +51,9 @@ class Executed(pr.IsScope):
|
||||
self.base = base
|
||||
self.var_args = var_args
|
||||
|
||||
def is_scope(self):
|
||||
return True
|
||||
|
||||
def get_parent_until(self, *args, **kwargs):
|
||||
return self.base.get_parent_until(*args, **kwargs)
|
||||
|
||||
@@ -278,6 +281,12 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
def isinstance(self, *cls):
|
||||
return isinstance(self.var, cls)
|
||||
|
||||
def is_scope(self):
|
||||
"""
|
||||
Since we inherit from Base, it would overwrite the action we want here.
|
||||
"""
|
||||
return self.var.is_scope()
|
||||
|
||||
def py__call__(self, evaluator, params):
|
||||
return Function.py__call__(self, evaluator, params)
|
||||
|
||||
@@ -285,7 +294,12 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
return "<%s of %s>" % (type(self).__name__, self.var)
|
||||
|
||||
|
||||
class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
|
||||
class Wrapper(pr.Base):
|
||||
def is_scope(self):
|
||||
return True
|
||||
|
||||
|
||||
class Class(use_metaclass(CachedMetaClass, Wrapper)):
|
||||
"""
|
||||
This class is not only important to extend `pr.Class`, it is also a
|
||||
important for descriptors (if the descriptor methods are evaluated or not).
|
||||
@@ -376,7 +390,7 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
|
||||
return "<e%s of %s>" % (type(self).__name__, self.base)
|
||||
|
||||
|
||||
class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
|
||||
class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
||||
"""
|
||||
Needed because of decorators. Decorators are evaluated here.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user