mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Move get_node() to tree_node and replace all the custom classdefs/funcdefs.
This commit is contained in:
@@ -367,7 +367,8 @@ class BaseDefinition(object):
|
||||
if isinstance(context, er.FunctionExecutionContext):
|
||||
# TODO the function context should be a part of the function
|
||||
# execution context.
|
||||
context = er.FunctionContext(self._evaluator, context.parent_context, context.funcdef)
|
||||
context = er.FunctionContext(
|
||||
self._evaluator, context.parent_context, context.tree_node)
|
||||
return Definition(self._evaluator, context.name)
|
||||
|
||||
def __repr__(self):
|
||||
@@ -690,7 +691,7 @@ class _Help(object):
|
||||
if followed:
|
||||
# TODO: Use all of the followed objects as input to Documentation.
|
||||
context = next(iter(followed))
|
||||
return context.get_node()
|
||||
return context.tree_node
|
||||
if self._name.tree_name is None:
|
||||
return None
|
||||
return self._name.tree_name.get_definition()
|
||||
|
||||
@@ -51,7 +51,7 @@ def get_user_scope(module_context, position):
|
||||
"""
|
||||
Returns the scope in which the user resides. This includes flows.
|
||||
"""
|
||||
user_stmt = module_context.module_node.get_statement_for_position(position)
|
||||
user_stmt = module_context.tree_node.get_statement_for_position(position)
|
||||
if user_stmt is None:
|
||||
def scan(scope):
|
||||
for s in scope.children:
|
||||
@@ -62,7 +62,7 @@ def get_user_scope(module_context, position):
|
||||
return scan(s)
|
||||
return None
|
||||
|
||||
scanned_node = scan(module_context.module_node)
|
||||
scanned_node = scan(module_context.tree_node)
|
||||
if scanned_node:
|
||||
return module_context.create_context(scanned_node, node_is_context=True)
|
||||
return module_context
|
||||
@@ -74,7 +74,7 @@ class Completion:
|
||||
def __init__(self, evaluator, module, code_lines, position, call_signatures_method):
|
||||
self._evaluator = evaluator
|
||||
self._module_context = module
|
||||
self._module_node = module.module_node
|
||||
self._module_node = module.tree_node
|
||||
self._code_lines = code_lines
|
||||
|
||||
# The first step of completions is to get the name
|
||||
@@ -197,7 +197,7 @@ class Completion:
|
||||
debug.dbg('trailer completion contexts: %s', contexts)
|
||||
for context in contexts:
|
||||
for filter in context.get_filters(
|
||||
search_global=False, origin_scope=user_context.get_node()):
|
||||
search_global=False, origin_scope=user_context.tree_node):
|
||||
completion_names += filter.values()
|
||||
return completion_names
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ def usages(evaluator, definition_names, mods):
|
||||
definition_names = set(resolve_names(definition_names))
|
||||
for m in imports.get_modules_containing_name(evaluator, mods, search_name):
|
||||
if isinstance(m, ModuleContext):
|
||||
for name_node in m.module_node.used_names.get(search_name, []):
|
||||
for name_node in m.tree_node.used_names.get(search_name, []):
|
||||
context = evaluator.create_context(m, name_node)
|
||||
result = evaluator.goto(context, name_node)
|
||||
if [c for c in compare_array(result) if c in compare_definitions]:
|
||||
|
||||
@@ -570,7 +570,7 @@ class Evaluator(object):
|
||||
return iterable.CompForContext.from_comp_for(parent_context, scope_node)
|
||||
raise Exception("There's a scope that was not managed.")
|
||||
|
||||
base_node = base_context.get_node()
|
||||
base_node = base_context.tree_node
|
||||
|
||||
if node_is_context and node.is_scope():
|
||||
scope_node = node
|
||||
|
||||
@@ -97,7 +97,7 @@ def _check_for_setattr(instance):
|
||||
if not isinstance(module, ModuleContext):
|
||||
return False
|
||||
|
||||
node = module.module_node
|
||||
node = module.tree_node
|
||||
try:
|
||||
stmts = node.used_names['setattr']
|
||||
except KeyError:
|
||||
|
||||
@@ -56,7 +56,7 @@ class CompiledObject(Context):
|
||||
super(CompiledObject, self).__init__(evaluator, parent_context)
|
||||
self.obj = obj
|
||||
# This attribute will not be set for most classes, except for fakes.
|
||||
self.classdef = faked_class
|
||||
self.tree_node = faked_class
|
||||
|
||||
def get_root_node(self):
|
||||
# To make things a bit easier with filters we add this method here.
|
||||
|
||||
@@ -190,9 +190,9 @@ def _get_faked(module, obj, name=None):
|
||||
|
||||
|
||||
def get_faked(evaluator, module, obj, name=None, parent_context=None):
|
||||
if parent_context and parent_context.classdef is not None:
|
||||
if parent_context and parent_context.tree_node is not None:
|
||||
# Try to search in already clearly defined stuff.
|
||||
found = _search_scope(parent_context.classdef, name)
|
||||
found = _search_scope(parent_context.tree_node, name)
|
||||
if found is not None:
|
||||
return found
|
||||
else:
|
||||
|
||||
@@ -36,7 +36,7 @@ class MixedObject(object):
|
||||
self.obj = compiled_object.obj
|
||||
self._tree_name = tree_name
|
||||
name_module = tree_name.get_root_node()
|
||||
if parent_context.get_node().get_root_node() != name_module:
|
||||
if parent_context.tree_node.get_root_node() != name_module:
|
||||
from jedi.evaluate.representation import ModuleContext
|
||||
module_context = ModuleContext(evaluator, name_module)
|
||||
name = compiled_object.get_root_context().py__name__()
|
||||
|
||||
@@ -8,14 +8,12 @@ class Context(object):
|
||||
To be defined by subclasses.
|
||||
"""
|
||||
predefined_names = {}
|
||||
tree_node = None
|
||||
|
||||
def __init__(self, evaluator, parent_context=None):
|
||||
self.evaluator = evaluator
|
||||
self.parent_context = parent_context
|
||||
|
||||
def get_node(self):
|
||||
return None
|
||||
|
||||
def get_parent_flow_context(self):
|
||||
return self.parent_context
|
||||
|
||||
@@ -75,7 +73,7 @@ class TreeContext(Context):
|
||||
self.predefined_names = {}
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s>' % (self.__class__.__name__, self.get_node())
|
||||
return '<%s: %s>' % (self.__class__.__name__, self.tree_node)
|
||||
|
||||
|
||||
class FlowContext(TreeContext):
|
||||
|
||||
@@ -137,7 +137,7 @@ def _search_function_executions(evaluator, module_context, funcdef):
|
||||
|
||||
def _get_possible_nodes(module_context, func_string_name):
|
||||
try:
|
||||
names = module_context.module_node.used_names[func_string_name]
|
||||
names = module_context.tree_node.used_names[func_string_name]
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
@@ -169,7 +169,7 @@ def _check_name_for_execution(evaluator, context, compare_node, name, trailer):
|
||||
yield execution
|
||||
|
||||
for value in evaluator.goto_definitions(context, name):
|
||||
value_node = value.get_node()
|
||||
value_node = value.tree_node
|
||||
if compare_node == value_node:
|
||||
for func_execution in create_func_excs():
|
||||
yield func_execution
|
||||
@@ -182,7 +182,7 @@ def _check_name_for_execution(evaluator, context, compare_node, name, trailer):
|
||||
if len(params) != 1:
|
||||
continue
|
||||
values = params[0].infer()
|
||||
nodes = [v.get_node() for v in values]
|
||||
nodes = [v.tree_node for v in values]
|
||||
if nodes == [compare_node]:
|
||||
# Found a decorator.
|
||||
module_context = context.get_root_context()
|
||||
|
||||
@@ -165,7 +165,8 @@ class AbstractUsedNamesFilter(AbstractFilter):
|
||||
|
||||
|
||||
class ParserTreeFilter(AbstractUsedNamesFilter):
|
||||
def __init__(self, evaluator, context, parser_scope, until_position=None, origin_scope=None):
|
||||
def __init__(self, evaluator, context, parser_scope, until_position=None,
|
||||
origin_scope=None, ):
|
||||
super(ParserTreeFilter, self).__init__(context, parser_scope)
|
||||
self._origin_scope = origin_scope
|
||||
self._until_position = until_position
|
||||
|
||||
@@ -55,7 +55,7 @@ class NameFinder(object):
|
||||
names = self.filter_name(filters)
|
||||
if self._found_predefined_types is not None and names:
|
||||
check = flow_analysis.reachability_check(
|
||||
self._context, self._context.get_node(), self._name)
|
||||
self._context, self._context.tree_node, self._name)
|
||||
if check is flow_analysis.UNREACHABLE:
|
||||
return set()
|
||||
return self._found_predefined_types
|
||||
@@ -148,7 +148,7 @@ class NameFinder(object):
|
||||
if not types and isinstance(self._name, tree.Name) and \
|
||||
not isinstance(self._name_context, AbstractInstanceContext):
|
||||
flow_scope = self._name
|
||||
base_node = self._name_context.get_node()
|
||||
base_node = self._name_context.tree_node
|
||||
if base_node.type == 'comp_for':
|
||||
return types
|
||||
while True:
|
||||
|
||||
@@ -82,7 +82,7 @@ class AbstractInstanceContext(Context):
|
||||
if include_self_names:
|
||||
for cls in self.class_context.py__mro__():
|
||||
if isinstance(cls, compiled.CompiledObject):
|
||||
if cls.classdef is not None:
|
||||
if cls.tree_node is not None:
|
||||
# In this case we're talking about a fake object, it
|
||||
# doesn't make sense for normal compiled objects to
|
||||
# search for self variables.
|
||||
@@ -152,7 +152,7 @@ class AbstractInstanceContext(Context):
|
||||
if node.parent.type in ('funcdef', 'classdef'):
|
||||
node = node.parent
|
||||
scope = node.get_parent_scope()
|
||||
if scope == class_context.classdef:
|
||||
if scope == class_context.tree_node:
|
||||
return class_context
|
||||
else:
|
||||
parent_context = self.create_instance_context(class_context, scope)
|
||||
@@ -225,7 +225,7 @@ class CompiledInstanceName(compiled.CompiledName):
|
||||
|
||||
yield BoundMethod(
|
||||
result_context.evaluator, self._instance, self.parent_context,
|
||||
parent_context, result_context.funcdef
|
||||
parent_context, result_context.tree_node
|
||||
)
|
||||
else:
|
||||
if result_context.api_type == 'function':
|
||||
@@ -268,7 +268,7 @@ class BoundMethod(er.FunctionContext):
|
||||
class CompiledBoundMethod(compiled.CompiledObject):
|
||||
def __init__(self, func):
|
||||
super(CompiledBoundMethod, self).__init__(
|
||||
func.evaluator, func.obj, func.parent_context, func.classdef)
|
||||
func.evaluator, func.obj, func.parent_context, func.tree_node)
|
||||
|
||||
def get_param_names(self):
|
||||
return list(super(CompiledBoundMethod, self).get_param_names())[1:]
|
||||
@@ -308,7 +308,7 @@ class LazyInstanceClassName(LazyInstanceName):
|
||||
|
||||
yield BoundMethod(
|
||||
result_context.evaluator, self._instance, self.class_context,
|
||||
parent_context, result_context.funcdef
|
||||
parent_context, result_context.tree_node
|
||||
)
|
||||
else:
|
||||
for c in er.apply_py__get__(result_context, self._instance):
|
||||
@@ -322,7 +322,7 @@ class InstanceClassFilter(filters.ParserTreeFilter):
|
||||
super(InstanceClassFilter, self).__init__(
|
||||
evaluator=evaluator,
|
||||
context=context,
|
||||
parser_scope=class_context.classdef,
|
||||
parser_scope=class_context.tree_node,
|
||||
origin_scope=origin_scope
|
||||
)
|
||||
self._class_context = class_context
|
||||
@@ -431,7 +431,7 @@ class InstanceVarArgs(object):
|
||||
class InstanceFunctionExecution(er.FunctionExecutionContext):
|
||||
def __init__(self, instance, parent_context, function_context, var_args):
|
||||
self.instance = instance
|
||||
var_args = InstanceVarArgs(instance, function_context.funcdef, var_args)
|
||||
var_args = InstanceVarArgs(instance, function_context.tree_node, var_args)
|
||||
|
||||
super(InstanceFunctionExecution, self).__init__(
|
||||
instance.evaluator, parent_context, function_context, var_args)
|
||||
|
||||
@@ -184,13 +184,13 @@ class CompForContext(context.TreeContext):
|
||||
|
||||
def __init__(self, evaluator, parent_context, comp_for):
|
||||
super(CompForContext, self).__init__(evaluator, parent_context)
|
||||
self.node = comp_for
|
||||
self.tree_node = comp_for
|
||||
|
||||
def get_node(self):
|
||||
return self.node
|
||||
return self.tree_node
|
||||
|
||||
def get_filters(self, search_global, until_position=None, origin_scope=None):
|
||||
yield ParserTreeFilter(self.evaluator, self, self.node)
|
||||
yield ParserTreeFilter(self.evaluator, self, self.tree_node)
|
||||
|
||||
|
||||
class Comprehension(AbstractSequence):
|
||||
@@ -758,12 +758,12 @@ def _check_array_additions(context, sequence):
|
||||
added_types = set()
|
||||
for add_name in search_names:
|
||||
try:
|
||||
possible_names = module_context.module_node.used_names[add_name]
|
||||
possible_names = module_context.tree_node.used_names[add_name]
|
||||
except KeyError:
|
||||
continue
|
||||
else:
|
||||
for name in possible_names:
|
||||
context_node = context.get_node()
|
||||
context_node = context.tree_node
|
||||
if not (context_node.start_pos < name.start_pos < context_node.end_pos):
|
||||
continue
|
||||
trailer = name.parent
|
||||
|
||||
@@ -71,7 +71,7 @@ def _fix_forward_reference(context, node):
|
||||
else:
|
||||
module = node.get_parent_until()
|
||||
new_node.move(module.end_pos[0])
|
||||
new_node.parent = context.get_node()
|
||||
new_node.parent = context.tree_node
|
||||
return new_node
|
||||
else:
|
||||
return node
|
||||
@@ -154,7 +154,7 @@ def py__getitem__(context, typ, node):
|
||||
assert len(factories) == 1
|
||||
factory = list(factories)[0]
|
||||
assert factory
|
||||
function_body_nodes = factory.funcdef.children[4].children
|
||||
function_body_nodes = factory.tree_node.children[4].children
|
||||
valid_classnames = set(child.name.value
|
||||
for child in function_body_nodes
|
||||
if isinstance(child, tree.Class))
|
||||
|
||||
@@ -75,12 +75,12 @@ class ExecutionRecursionDetector(object):
|
||||
self.recursion_level -= 1
|
||||
|
||||
def push_execution(self, execution):
|
||||
in_par_execution_funcs = execution.funcdef in self.parent_execution_funcs
|
||||
in_execution_funcs = execution.funcdef in self.execution_funcs
|
||||
in_par_execution_funcs = execution.tree_node in self.parent_execution_funcs
|
||||
in_execution_funcs = execution.tree_node in self.execution_funcs
|
||||
self.recursion_level += 1
|
||||
self.execution_count += 1
|
||||
self.execution_funcs.add(execution.funcdef)
|
||||
self.parent_execution_funcs.append(execution.funcdef)
|
||||
self.execution_funcs.add(execution.tree_node)
|
||||
self.parent_execution_funcs.append(execution.tree_node)
|
||||
|
||||
if self.execution_count > settings.max_executions:
|
||||
return True
|
||||
|
||||
@@ -105,10 +105,7 @@ class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
|
||||
def __init__(self, evaluator, classdef, parent_context):
|
||||
super(ClassContext, self).__init__(evaluator, parent_context=parent_context)
|
||||
self.classdef = classdef
|
||||
|
||||
def get_node(self):
|
||||
return self.classdef
|
||||
self.tree_node = classdef
|
||||
|
||||
@memoize_default(default=())
|
||||
def py__mro__(self):
|
||||
@@ -148,7 +145,7 @@ class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
|
||||
@memoize_default(default=())
|
||||
def py__bases__(self):
|
||||
arglist = self.classdef.get_super_arglist()
|
||||
arglist = self.tree_node.get_super_arglist()
|
||||
if arglist:
|
||||
args = param.TreeArguments(self.evaluator, self, arglist)
|
||||
return [value for key, value in args.unpack() if key is None]
|
||||
@@ -169,14 +166,17 @@ class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
|
||||
def get_filters(self, search_global, until_position=None, origin_scope=None, is_instance=False):
|
||||
if search_global:
|
||||
yield ParserTreeFilter(self.evaluator, self, self.classdef, until_position, origin_scope=origin_scope)
|
||||
yield ParserTreeFilter(self.evaluator, self, self.tree_node, until_position, origin_scope=origin_scope)
|
||||
else:
|
||||
for scope in self.py__mro__():
|
||||
print(scope)
|
||||
if isinstance(scope, compiled.CompiledObject):
|
||||
for filter in scope.get_filters(is_instance=is_instance):
|
||||
yield filter
|
||||
else:
|
||||
yield ClassFilter(self.evaluator, self, scope.classdef, origin_scope=origin_scope)
|
||||
yield ClassFilter(
|
||||
self.evaluator, self, scope.tree_node,
|
||||
origin_scope=origin_scope)
|
||||
|
||||
def is_class(self):
|
||||
return True
|
||||
@@ -209,7 +209,7 @@ class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return ContextName(self, self.classdef.name)
|
||||
return ContextName(self, self.tree_node.name)
|
||||
|
||||
|
||||
class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
@@ -221,14 +221,11 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
def __init__(self, evaluator, parent_context, funcdef):
|
||||
""" This should not be called directly """
|
||||
super(FunctionContext, self).__init__(evaluator, parent_context)
|
||||
self.base = self.base_func = self.funcdef = funcdef
|
||||
|
||||
def get_node(self):
|
||||
return self.funcdef
|
||||
self.tree_node = funcdef
|
||||
|
||||
def get_filters(self, search_global, until_position=None, origin_scope=None):
|
||||
if search_global:
|
||||
yield ParserTreeFilter(self.evaluator, self, self.base, until_position, origin_scope=origin_scope)
|
||||
yield ParserTreeFilter(self.evaluator, self, self.tree_node, until_position, origin_scope=origin_scope)
|
||||
else:
|
||||
scope = self.py__class__()
|
||||
for filter in scope.get_filters(search_global=False, origin_scope=origin_scope):
|
||||
@@ -238,7 +235,7 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
"""
|
||||
Created to be used by inheritance.
|
||||
"""
|
||||
if self.base.is_generator():
|
||||
if self.tree_node.is_generator():
|
||||
return set([iterable.Generator(self.evaluator, function_execution)])
|
||||
else:
|
||||
return function_execution.get_return_values()
|
||||
@@ -257,7 +254,7 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
def py__class__(self):
|
||||
# This differentiation is only necessary for Python2. Python3 does not
|
||||
# use a different method class.
|
||||
if isinstance(self.base.get_parent_scope(), tree.Class):
|
||||
if isinstance(self.tree_node.get_parent_scope(), tree.Class):
|
||||
name = 'METHOD_CLASS'
|
||||
else:
|
||||
name = 'FUNCTION_CLASS'
|
||||
@@ -265,11 +262,11 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return ContextName(self, self.funcdef.name)
|
||||
return ContextName(self, self.tree_node.name)
|
||||
|
||||
def get_param_names(self):
|
||||
function_execution = self.get_function_execution()
|
||||
return [ParamName(function_execution, param.name) for param in self.funcdef.params]
|
||||
return [ParamName(function_execution, param.name) for param in self.tree_node.params]
|
||||
|
||||
|
||||
class FunctionExecutionContext(Executed):
|
||||
@@ -286,15 +283,12 @@ class FunctionExecutionContext(Executed):
|
||||
def __init__(self, evaluator, parent_context, function_context, var_args):
|
||||
super(FunctionExecutionContext, self).__init__(evaluator, parent_context, var_args)
|
||||
self.function_context = function_context
|
||||
self.funcdef = function_context.funcdef
|
||||
|
||||
def get_node(self):
|
||||
return self.function_context.funcdef
|
||||
self.tree_node = function_context.tree_node
|
||||
|
||||
@memoize_default(default=set())
|
||||
@recursion.execution_recursion_decorator
|
||||
def get_return_values(self, check_yields=False):
|
||||
funcdef = self.funcdef
|
||||
funcdef = self.tree_node
|
||||
if funcdef.type == 'lambda':
|
||||
return self.evaluator.eval_element(self, funcdef.children[-1])
|
||||
|
||||
@@ -335,7 +329,7 @@ class FunctionExecutionContext(Executed):
|
||||
def get_yield_values(self):
|
||||
for_parents = [(y, tree.search_ancestor(y, ('for_stmt', 'funcdef',
|
||||
'while_stmt', 'if_stmt')))
|
||||
for y in self.funcdef.yields]
|
||||
for y in self.tree_node.yields]
|
||||
|
||||
# Calculate if the yields are placed within the same for loop.
|
||||
yields_order = []
|
||||
@@ -346,13 +340,13 @@ class FunctionExecutionContext(Executed):
|
||||
parent = for_stmt.parent
|
||||
if parent.type == 'suite':
|
||||
parent = parent.parent
|
||||
if for_stmt.type == 'for_stmt' and parent == self.funcdef \
|
||||
if for_stmt.type == 'for_stmt' and parent == self.tree_node \
|
||||
and for_stmt.defines_one_name(): # Simplicity for now.
|
||||
if for_stmt == last_for_stmt:
|
||||
yields_order[-1][1].append(yield_)
|
||||
else:
|
||||
yields_order.append((for_stmt, [yield_]))
|
||||
elif for_stmt == self.funcdef:
|
||||
elif for_stmt == self.tree_node:
|
||||
yields_order.append((None, [yield_]))
|
||||
else:
|
||||
yield self.get_return_values(check_yields=True)
|
||||
@@ -378,13 +372,13 @@ class FunctionExecutionContext(Executed):
|
||||
yield result
|
||||
|
||||
def get_filters(self, search_global, until_position=None, origin_scope=None):
|
||||
yield self.function_execution_filter(self.evaluator, self, self.funcdef,
|
||||
yield self.function_execution_filter(self.evaluator, self, self.tree_node,
|
||||
until_position,
|
||||
origin_scope=origin_scope)
|
||||
|
||||
@memoize_default(default=NO_DEFAULT)
|
||||
def get_params(self):
|
||||
return param.get_params(self.evaluator, self.parent_context, self.funcdef, self.var_args)
|
||||
return param.get_params(self.evaluator, self.parent_context, self.tree_node, self.var_args)
|
||||
|
||||
|
||||
class AnonymousFunctionExecution(FunctionExecutionContext):
|
||||
@@ -395,7 +389,7 @@ class AnonymousFunctionExecution(FunctionExecutionContext):
|
||||
@memoize_default(default=NO_DEFAULT)
|
||||
def get_params(self):
|
||||
# We need to do a dynamic search here.
|
||||
return search_params(self.evaluator, self.parent_context, self.funcdef)
|
||||
return search_params(self.evaluator, self.parent_context, self.tree_node)
|
||||
|
||||
|
||||
class ModuleAttributeName(AbstractNameDefinition):
|
||||
@@ -420,20 +414,17 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
|
||||
def __init__(self, evaluator, module_node):
|
||||
super(ModuleContext, self).__init__(evaluator, parent_context=None)
|
||||
self.module_node = module_node
|
||||
|
||||
def get_node(self):
|
||||
return self.module_node
|
||||
self.tree_node = module_node
|
||||
|
||||
def get_filters(self, search_global, until_position=None, origin_scope=None):
|
||||
yield ParserTreeFilter(
|
||||
self.evaluator,
|
||||
self,
|
||||
self.module_node,
|
||||
self.tree_node,
|
||||
until_position,
|
||||
origin_scope=origin_scope
|
||||
)
|
||||
yield GlobalNameFilter(self, self.module_node)
|
||||
yield GlobalNameFilter(self, self.tree_node)
|
||||
yield DictFilter(self._sub_modules_dict())
|
||||
yield DictFilter(self._module_attributes_dict())
|
||||
for star_module in self.star_imports():
|
||||
@@ -445,7 +436,7 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
@memoize_default([])
|
||||
def star_imports(self):
|
||||
modules = []
|
||||
for i in self.module_node.imports:
|
||||
for i in self.tree_node.imports:
|
||||
if i.is_star_import():
|
||||
name = i.star_import_name()
|
||||
new = imports.infer_import(self, name)
|
||||
@@ -464,7 +455,7 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
@property
|
||||
@memoize_default()
|
||||
def name(self):
|
||||
return ContextName(self, self.module_node.name)
|
||||
return ContextName(self, self.tree_node.name)
|
||||
|
||||
def _get_init_directory(self):
|
||||
"""
|
||||
@@ -490,10 +481,10 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
"""
|
||||
In contrast to Python's __file__ can be None.
|
||||
"""
|
||||
if self.module_node.path is None:
|
||||
if self.tree_node.path is None:
|
||||
return None
|
||||
|
||||
return os.path.abspath(self.module_node.path)
|
||||
return os.path.abspath(self.tree_node.path)
|
||||
|
||||
def py__package__(self):
|
||||
if self._get_init_directory() is None:
|
||||
@@ -551,7 +542,7 @@ class ModuleContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||
Lists modules in the directory of this module (if this module is a
|
||||
package).
|
||||
"""
|
||||
path = self.module_node.path
|
||||
path = self.tree_node.path
|
||||
names = {}
|
||||
if path is not None and path.endswith(os.path.sep + '__init__.py'):
|
||||
mods = pkgutil.iter_modules([os.path.dirname(path)])
|
||||
|
||||
@@ -167,7 +167,7 @@ def _check_module(module_context):
|
||||
return sys_path
|
||||
|
||||
try:
|
||||
possible_names = module_context.get_node().used_names['path']
|
||||
possible_names = module_context.tree_node.used_names['path']
|
||||
except KeyError:
|
||||
# module.used_names is MergedNamesDict whose getitem never throws
|
||||
# keyerror, this is superfluous.
|
||||
|
||||
@@ -30,3 +30,16 @@ class Y(X):
|
||||
|
||||
#? []
|
||||
myfoobar
|
||||
|
||||
# -----------------
|
||||
# Inheritance
|
||||
# -----------------
|
||||
|
||||
class Super():
|
||||
enabled = True
|
||||
if enabled:
|
||||
yo_dude = 4
|
||||
|
||||
class Sub(Super):
|
||||
#? ['yo_dude']
|
||||
yo_dud
|
||||
|
||||
@@ -291,16 +291,3 @@ elif 3 == flow_import.env:
|
||||
|
||||
#? int() str()
|
||||
a
|
||||
|
||||
# -----------------
|
||||
# Inheritance
|
||||
# -----------------
|
||||
|
||||
class Super():
|
||||
enabled = True
|
||||
if enabled:
|
||||
yo_dude = 4
|
||||
|
||||
class Sub(Super):
|
||||
#? ['yo_dude']
|
||||
yo_dud
|
||||
|
||||
@@ -195,7 +195,7 @@ class IntegrationTestCase(object):
|
||||
user_context = get_user_scope(module_context, (self.line_nr, 0))
|
||||
if user_context.api_type == 'function':
|
||||
user_context = user_context.get_function_execution()
|
||||
element.parent = user_context.get_node()
|
||||
element.parent = user_context.tree_node
|
||||
results = evaluator.eval_element(user_context, element)
|
||||
if not results:
|
||||
raise Exception('Could not resolve %s on line %s'
|
||||
|
||||
@@ -33,7 +33,7 @@ def test_fake_loading():
|
||||
|
||||
|
||||
def test_fake_docstr():
|
||||
assert compiled.create(_evaluator(), next).get_node().raw_doc == next.__doc__
|
||||
assert compiled.create(_evaluator(), next).tree_node.raw_doc == next.__doc__
|
||||
|
||||
|
||||
def test_parse_function_doc_illegal_docstr():
|
||||
|
||||
@@ -257,7 +257,7 @@ def test_string_literals():
|
||||
""")
|
||||
|
||||
script = jedi.Script(dedent(source))
|
||||
script._get_module().module_node.end_pos == (6, 0)
|
||||
script._get_module().tree_node.end_pos == (6, 0)
|
||||
assert script.completions()
|
||||
|
||||
|
||||
@@ -275,7 +275,7 @@ def test_decorator_string_issue():
|
||||
|
||||
s = jedi.Script(source)
|
||||
assert s.completions()
|
||||
assert s._get_module().module_node.get_code() == source
|
||||
assert s._get_module().tree_node.get_code() == source
|
||||
|
||||
|
||||
def test_round_trip():
|
||||
|
||||
@@ -175,7 +175,7 @@ class TestRegression(TestCase):
|
||||
completions = Script('').completions()
|
||||
c = get_str_completion(completions)
|
||||
str_context, = c._name.infer()
|
||||
n = len(str_context.classdef.children[-1].children)
|
||||
n = len(str_context.tree_node.children[-1].children)
|
||||
if i == 0:
|
||||
limit = n
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user