forked from VimPlug/jedi
execution_value -> execution_context
This commit is contained in:
@@ -144,8 +144,8 @@ class _AbstractArgumentsMixin(object):
|
||||
def unpack(self, funcdef=None):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_executed_params_and_issues(self, execution_value):
|
||||
return get_executed_params_and_issues(execution_value, self)
|
||||
def get_executed_params_and_issues(self, execution_context):
|
||||
return get_executed_params_and_issues(execution_context, self)
|
||||
|
||||
def get_calling_nodes(self):
|
||||
return []
|
||||
@@ -158,12 +158,12 @@ class AbstractArguments(_AbstractArgumentsMixin):
|
||||
|
||||
|
||||
class AnonymousArguments(AbstractArguments):
|
||||
def get_executed_params_and_issues(self, execution_value):
|
||||
def get_executed_params_and_issues(self, execution_context):
|
||||
from jedi.inference.dynamic import search_params
|
||||
return search_params(
|
||||
execution_value.inference_state,
|
||||
execution_value,
|
||||
execution_value.tree_node
|
||||
execution_context.inference_state,
|
||||
execution_context,
|
||||
execution_context.tree_node
|
||||
), []
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@@ -27,7 +27,6 @@ class AbstractContext(object):
|
||||
def goto(self, name_or_str, position):
|
||||
from jedi.inference import finder
|
||||
f = finder.NameFinder(self.inference_state, self, self, name_or_str, position)
|
||||
raise NotImplementedError('this does not seem to be correct')
|
||||
filters = f.get_global_filters()
|
||||
return f.filter_name(filters)
|
||||
|
||||
|
||||
@@ -227,12 +227,12 @@ def _infer_for_statement_string(module_value, string):
|
||||
module_value,
|
||||
funcdef
|
||||
)
|
||||
func_execution_value = function_value.get_function_execution()
|
||||
func_execution_context = function_value.get_function_execution()
|
||||
# Use the module of the param.
|
||||
# TODO this module is not the module of the param in case of a function
|
||||
# call. In that case it's the module of the function call.
|
||||
# stuffed with content from a function call.
|
||||
return list(_execute_types_in_stmt(func_execution_value, stmt))
|
||||
return list(_execute_types_in_stmt(func_execution_context, stmt))
|
||||
|
||||
|
||||
def _execute_types_in_stmt(module_value, stmt):
|
||||
@@ -268,7 +268,7 @@ def _execute_array_values(inference_state, array):
|
||||
|
||||
|
||||
@inference_state_method_cache()
|
||||
def infer_param(execution_value, param):
|
||||
def infer_param(execution_context, param):
|
||||
from jedi.inference.value.instance import InstanceArguments
|
||||
from jedi.inference.value import FunctionExecutionContext
|
||||
|
||||
@@ -278,16 +278,16 @@ def infer_param(execution_value, param):
|
||||
for param_str in _search_param_in_docstr(docstring, param.name.value)
|
||||
for p in _infer_for_statement_string(module_context, param_str)
|
||||
)
|
||||
module_context = execution_value.get_root_context()
|
||||
module_context = execution_context.get_root_context()
|
||||
func = param.get_parent_function()
|
||||
if func.type == 'lambdef':
|
||||
return NO_VALUES
|
||||
|
||||
types = infer_docstring(execution_value.py__doc__())
|
||||
if isinstance(execution_value, FunctionExecutionContext) \
|
||||
and isinstance(execution_value.var_args, InstanceArguments) \
|
||||
and execution_value.function_value.py__name__() == '__init__':
|
||||
class_value = execution_value.var_args.instance.class_value
|
||||
types = infer_docstring(execution_context.py__doc__())
|
||||
if isinstance(execution_context, FunctionExecutionContext) \
|
||||
and isinstance(execution_context.var_args, InstanceArguments) \
|
||||
and execution_context.function_value.py__name__() == '__init__':
|
||||
class_value = execution_context.var_args.instance.class_value
|
||||
types |= infer_docstring(class_value.py__doc__())
|
||||
|
||||
debug.dbg('Found param types for docstring: %s', types, color='BLUE')
|
||||
|
||||
@@ -54,7 +54,7 @@ class DynamicExecutedParams(object):
|
||||
|
||||
|
||||
@debug.increase_indent
|
||||
def search_params(inference_state, execution_value, funcdef):
|
||||
def search_params(inference_state, execution_context, funcdef):
|
||||
"""
|
||||
A dynamic search for param values. If you try to complete a type:
|
||||
|
||||
@@ -68,28 +68,28 @@ def search_params(inference_state, execution_value, funcdef):
|
||||
is.
|
||||
"""
|
||||
if not settings.dynamic_params:
|
||||
return create_default_params(execution_value, funcdef)
|
||||
return create_default_params(execution_context, funcdef)
|
||||
|
||||
inference_state.dynamic_params_depth += 1
|
||||
try:
|
||||
path = execution_value.get_root_context().py__file__()
|
||||
path = execution_context.get_root_context().py__file__()
|
||||
if path is not None and is_stdlib_path(path):
|
||||
# We don't want to search for usages in the stdlib. Usually people
|
||||
# don't work with it (except if you are a core maintainer, sorry).
|
||||
# This makes everything slower. Just disable it and run the tests,
|
||||
# you will see the slowdown, especially in 3.6.
|
||||
return create_default_params(execution_value, funcdef)
|
||||
return create_default_params(execution_context, funcdef)
|
||||
|
||||
if funcdef.type == 'lambdef':
|
||||
string_name = _get_lambda_name(funcdef)
|
||||
if string_name is None:
|
||||
return create_default_params(execution_value, funcdef)
|
||||
return create_default_params(execution_context, funcdef)
|
||||
else:
|
||||
string_name = funcdef.name.value
|
||||
debug.dbg('Dynamic param search in %s.', string_name, color='MAGENTA')
|
||||
|
||||
try:
|
||||
module_context = execution_value.get_root_context()
|
||||
module_context = execution_context.get_root_context()
|
||||
function_executions = _search_function_executions(
|
||||
inference_state,
|
||||
module_context,
|
||||
@@ -105,7 +105,7 @@ def search_params(inference_state, execution_value, funcdef):
|
||||
for executed_params in zipped_params]
|
||||
# Inferes the ExecutedParams to types.
|
||||
else:
|
||||
return create_default_params(execution_value, funcdef)
|
||||
return create_default_params(execution_context, funcdef)
|
||||
finally:
|
||||
debug.dbg('Dynamic param result finished', color='MAGENTA')
|
||||
return params
|
||||
@@ -218,11 +218,11 @@ def _check_name_for_execution(inference_state, value, compare_node, name, traile
|
||||
if nodes == [compare_node]:
|
||||
# Found a decorator.
|
||||
module_value = value.get_root_context()
|
||||
execution_value = next(create_func_excs())
|
||||
execution_context = next(create_func_excs())
|
||||
for name, trailer in _get_possible_nodes(module_context, params[0].string_name):
|
||||
if value_node.start_pos < name.start_pos < value_node.end_pos:
|
||||
raise NotImplementedError
|
||||
random_value = inference_state.create_context(execution_value, name)
|
||||
random_value = inference_state.create_context(execution_context, name)
|
||||
iterator = _check_name_for_execution(
|
||||
inference_state,
|
||||
random_value,
|
||||
|
||||
@@ -107,9 +107,9 @@ def _split_comment_param_declaration(decl_text):
|
||||
|
||||
|
||||
@inference_state_method_cache()
|
||||
def infer_param(execution_value, param):
|
||||
values = _infer_param(execution_value, param)
|
||||
inference_state = execution_value.inference_state
|
||||
def infer_param(execution_context, param):
|
||||
values = _infer_param(execution_context, param)
|
||||
inference_state = execution_context.inference_state
|
||||
if param.star_count == 1:
|
||||
tuple_ = builtin_from_name(inference_state, 'tuple')
|
||||
return ValueSet([GenericClass(
|
||||
@@ -126,7 +126,7 @@ def infer_param(execution_value, param):
|
||||
return values
|
||||
|
||||
|
||||
def _infer_param(execution_value, param):
|
||||
def _infer_param(execution_context, param):
|
||||
"""
|
||||
Infers the type of a function parameter, using type annotations.
|
||||
"""
|
||||
@@ -159,7 +159,7 @@ def _infer_param(execution_value, param):
|
||||
params_comments, all_params
|
||||
)
|
||||
from jedi.inference.value.instance import InstanceArguments
|
||||
if isinstance(execution_value.var_args, InstanceArguments):
|
||||
if isinstance(execution_context.var_args, InstanceArguments):
|
||||
if index == 0:
|
||||
# Assume it's self, which is already handled
|
||||
return NO_VALUES
|
||||
@@ -169,11 +169,11 @@ def _infer_param(execution_value, param):
|
||||
|
||||
param_comment = params_comments[index]
|
||||
return _infer_annotation_string(
|
||||
execution_value.function_value.get_default_param_value(),
|
||||
execution_context.function_value.get_default_param_value(),
|
||||
param_comment
|
||||
)
|
||||
# Annotations are like default params and resolve in the same way.
|
||||
value = execution_value.function_value.get_default_param_value()
|
||||
value = execution_context.function_value.get_default_param_value()
|
||||
return infer_annotation(value, annotation)
|
||||
|
||||
|
||||
@@ -191,16 +191,16 @@ def py__annotations__(funcdef):
|
||||
|
||||
|
||||
@inference_state_method_cache()
|
||||
def infer_return_types(function_execution_value):
|
||||
def infer_return_types(function_execution_context):
|
||||
"""
|
||||
Infers the type of a function's return value,
|
||||
according to type annotations.
|
||||
"""
|
||||
all_annotations = py__annotations__(function_execution_value.tree_node)
|
||||
all_annotations = py__annotations__(function_execution_context.tree_node)
|
||||
annotation = all_annotations.get("return", None)
|
||||
if annotation is None:
|
||||
# If there is no Python 3-type annotation, look for a Python 2-type annotation
|
||||
node = function_execution_value.tree_node
|
||||
node = function_execution_context.tree_node
|
||||
comment = parser_utils.get_following_comment_same_line(node)
|
||||
if comment is None:
|
||||
return NO_VALUES
|
||||
@@ -210,19 +210,19 @@ def infer_return_types(function_execution_value):
|
||||
return NO_VALUES
|
||||
|
||||
return _infer_annotation_string(
|
||||
function_execution_value.function_value.get_default_param_value(),
|
||||
function_execution_context.function_value.get_default_param_value(),
|
||||
match.group(1).strip()
|
||||
).execute_annotation()
|
||||
if annotation is None:
|
||||
return NO_VALUES
|
||||
|
||||
value = function_execution_value.function_value.get_default_param_value()
|
||||
value = function_execution_context.function_value.get_default_param_value()
|
||||
unknown_type_vars = list(find_unknown_type_vars(value, annotation))
|
||||
annotation_values = infer_annotation(value, annotation)
|
||||
if not unknown_type_vars:
|
||||
return annotation_values.execute_annotation()
|
||||
|
||||
type_var_dict = infer_type_vars_for_execution(function_execution_value, all_annotations)
|
||||
type_var_dict = infer_type_vars_for_execution(function_execution_context, all_annotations)
|
||||
|
||||
return ValueSet.from_sets(
|
||||
ann.define_generics(type_var_dict)
|
||||
@@ -231,7 +231,7 @@ def infer_return_types(function_execution_value):
|
||||
).execute_annotation()
|
||||
|
||||
|
||||
def infer_type_vars_for_execution(execution_value, annotation_dict):
|
||||
def infer_type_vars_for_execution(execution_context, annotation_dict):
|
||||
"""
|
||||
Some functions use type vars that are not defined by the class, but rather
|
||||
only defined in the function. See for example `iter`. In those cases we
|
||||
@@ -241,10 +241,10 @@ def infer_type_vars_for_execution(execution_value, annotation_dict):
|
||||
2. Infer type vars with the execution state we have.
|
||||
3. Return the union of all type vars that have been found.
|
||||
"""
|
||||
value = execution_value.function_value.get_default_param_value()
|
||||
value = execution_context.function_value.get_default_param_value()
|
||||
|
||||
annotation_variable_results = {}
|
||||
executed_params, _ = execution_value.get_executed_params_and_issues()
|
||||
executed_params, _ = execution_context.get_executed_params_and_issues()
|
||||
for executed_param in executed_params:
|
||||
try:
|
||||
annotation_node = annotation_dict[executed_param.string_name]
|
||||
|
||||
@@ -19,8 +19,8 @@ def _add_argument_issue(error_name, lazy_value, message):
|
||||
|
||||
class ExecutedParam(object):
|
||||
"""Fake a param and give it values."""
|
||||
def __init__(self, execution_value, param_node, lazy_value, is_default=False):
|
||||
self._execution_value = execution_value
|
||||
def __init__(self, execution_context, param_node, lazy_value, is_default=False):
|
||||
self._execution_context = execution_context
|
||||
self._param_node = param_node
|
||||
self._lazy_value = lazy_value
|
||||
self.string_name = param_node.name.value
|
||||
@@ -28,11 +28,11 @@ class ExecutedParam(object):
|
||||
|
||||
def infer_annotations(self):
|
||||
from jedi.inference.gradual.annotation import infer_param
|
||||
return infer_param(self._execution_value, self._param_node)
|
||||
return infer_param(self._execution_context, self._param_node)
|
||||
|
||||
def infer(self, use_hints=True):
|
||||
if use_hints:
|
||||
doc_params = docstrings.infer_param(self._execution_value, self._param_node)
|
||||
doc_params = docstrings.infer_param(self._execution_context, self._param_node)
|
||||
ann = self.infer_annotations().execute_annotation()
|
||||
if ann or doc_params:
|
||||
return ann | doc_params
|
||||
@@ -59,13 +59,13 @@ class ExecutedParam(object):
|
||||
|
||||
@property
|
||||
def var_args(self):
|
||||
return self._execution_value.var_args
|
||||
return self._execution_context.var_args
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s>' % (self.__class__.__name__, self.string_name)
|
||||
|
||||
|
||||
def get_executed_params_and_issues(execution_value, arguments):
|
||||
def get_executed_params_and_issues(execution_context, arguments):
|
||||
def too_many_args(argument):
|
||||
m = _error_argument_count(funcdef, len(unpacked_va))
|
||||
# Just report an error for the first param that is not needed (like
|
||||
@@ -85,11 +85,11 @@ def get_executed_params_and_issues(execution_value, arguments):
|
||||
issues = [] # List[Optional[analysis issue]]
|
||||
result_params = []
|
||||
param_dict = {}
|
||||
funcdef = execution_value.tree_node
|
||||
funcdef = execution_context.tree_node
|
||||
# Default params are part of the value where the function was defined.
|
||||
# This means that they might have access on class variables that the
|
||||
# function itself doesn't have.
|
||||
default_param_value = execution_value.function_value.get_default_param_value()
|
||||
default_param_value = execution_context.function_value.get_default_param_value()
|
||||
|
||||
for param in funcdef.get_params():
|
||||
param_dict[param.name.value] = param
|
||||
@@ -125,7 +125,7 @@ def get_executed_params_and_issues(execution_value, arguments):
|
||||
valueualized_node.node, message=m)
|
||||
)
|
||||
else:
|
||||
keys_used[key] = ExecutedParam(execution_value, key_param, argument)
|
||||
keys_used[key] = ExecutedParam(execution_context, key_param, argument)
|
||||
key, argument = next(var_arg_iterator, (None, None))
|
||||
|
||||
try:
|
||||
@@ -145,13 +145,13 @@ def get_executed_params_and_issues(execution_value, arguments):
|
||||
var_arg_iterator.push_back((key, argument))
|
||||
break
|
||||
lazy_value_list.append(argument)
|
||||
seq = iterable.FakeSequence(execution_value.inference_state, u'tuple', lazy_value_list)
|
||||
seq = iterable.FakeSequence(execution_context.inference_state, u'tuple', lazy_value_list)
|
||||
result_arg = LazyKnownValue(seq)
|
||||
elif param.star_count == 2:
|
||||
if argument is not None:
|
||||
too_many_args(argument)
|
||||
# **kwargs param
|
||||
dct = iterable.FakeDict(execution_value.inference_state, dict(non_matching_keys))
|
||||
dct = iterable.FakeDict(execution_context.inference_state, dict(non_matching_keys))
|
||||
result_arg = LazyKnownValue(dct)
|
||||
non_matching_keys = {}
|
||||
else:
|
||||
@@ -178,7 +178,7 @@ def get_executed_params_and_issues(execution_value, arguments):
|
||||
result_arg = argument
|
||||
|
||||
result_params.append(ExecutedParam(
|
||||
execution_value, param, result_arg,
|
||||
execution_context, param, result_arg,
|
||||
is_default=is_default
|
||||
))
|
||||
if not isinstance(result_arg, LazyUnknownValue):
|
||||
@@ -232,22 +232,22 @@ def _error_argument_count(funcdef, actual_count):
|
||||
% (funcdef.name, before, len(params), actual_count))
|
||||
|
||||
|
||||
def _create_default_param(execution_value, param):
|
||||
def _create_default_param(execution_context, param):
|
||||
if param.star_count == 1:
|
||||
result_arg = LazyKnownValue(
|
||||
iterable.FakeSequence(execution_value.inference_state, u'tuple', [])
|
||||
iterable.FakeSequence(execution_context.inference_state, u'tuple', [])
|
||||
)
|
||||
elif param.star_count == 2:
|
||||
result_arg = LazyKnownValue(
|
||||
iterable.FakeDict(execution_value.inference_state, {})
|
||||
iterable.FakeDict(execution_context.inference_state, {})
|
||||
)
|
||||
elif param.default is None:
|
||||
result_arg = LazyUnknownValue()
|
||||
else:
|
||||
result_arg = LazyTreeValue(execution_value.parent_context, param.default)
|
||||
return ExecutedParam(execution_value, param, result_arg)
|
||||
result_arg = LazyTreeValue(execution_context.parent_context, param.default)
|
||||
return ExecutedParam(execution_context, param, result_arg)
|
||||
|
||||
|
||||
def create_default_params(execution_value, funcdef):
|
||||
return [_create_default_param(execution_value, p)
|
||||
def create_default_params(execution_context, funcdef):
|
||||
return [_create_default_param(execution_context, p)
|
||||
for p in funcdef.get_params()]
|
||||
|
||||
@@ -20,8 +20,8 @@ def _iter_nodes_for_param(param_name):
|
||||
from parso.python.tree import search_ancestor
|
||||
from jedi.inference.arguments import TreeArguments
|
||||
|
||||
execution_value = param_name.parent_context
|
||||
function_node = execution_value.tree_node
|
||||
execution_context = param_name.parent_context
|
||||
function_node = execution_context.tree_node
|
||||
module_node = function_node.get_root_node()
|
||||
start = function_node.children[-1].start_pos
|
||||
end = function_node.children[-1].end_pos
|
||||
@@ -36,12 +36,12 @@ def _iter_nodes_for_param(param_name):
|
||||
trailer = search_ancestor(argument, 'trailer')
|
||||
if trailer is not None: # Make sure we're in a function
|
||||
raise NotImplementedError
|
||||
context = execution_value.create_context(trailer)
|
||||
context = execution_context.create_context(trailer)
|
||||
if _goes_to_param_name(param_name, context, name):
|
||||
values = _to_callables(context, trailer)
|
||||
|
||||
args = TreeArguments.create_cached(
|
||||
execution_value.inference_state,
|
||||
execution_context.inference_state,
|
||||
context=context,
|
||||
argument_node=trailer.children[1],
|
||||
trailer=trailer,
|
||||
|
||||
@@ -38,9 +38,9 @@ class AnonymousInstanceArguments(AnonymousArguments):
|
||||
def __init__(self, instance):
|
||||
self._instance = instance
|
||||
|
||||
def get_executed_params_and_issues(self, execution_value):
|
||||
def get_executed_params_and_issues(self, execution_context):
|
||||
from jedi.inference.dynamic import search_params
|
||||
tree_params = execution_value.tree_node.get_params()
|
||||
tree_params = execution_context.tree_node.get_params()
|
||||
if not tree_params:
|
||||
return [], []
|
||||
|
||||
@@ -50,9 +50,9 @@ class AnonymousInstanceArguments(AnonymousArguments):
|
||||
# executions of this function, we have all the params already.
|
||||
return [self_param], []
|
||||
executed_params = list(search_params(
|
||||
execution_value.inference_state,
|
||||
execution_value,
|
||||
execution_value.tree_node
|
||||
execution_context.inference_state,
|
||||
execution_context,
|
||||
execution_context.tree_node
|
||||
))
|
||||
executed_params[0] = self_param
|
||||
return executed_params, []
|
||||
@@ -520,8 +520,8 @@ class InstanceArguments(TreeArgumentsWrapper):
|
||||
for values in self._wrapped_arguments.unpack(func):
|
||||
yield values
|
||||
|
||||
def get_executed_params_and_issues(self, execution_value):
|
||||
def get_executed_params_and_issues(self, execution_context):
|
||||
if isinstance(self._wrapped_arguments, AnonymousInstanceArguments):
|
||||
return self._wrapped_arguments.get_executed_params_and_issues(execution_value)
|
||||
return self._wrapped_arguments.get_executed_params_and_issues(execution_context)
|
||||
|
||||
return super(InstanceArguments, self).get_executed_params_and_issues(execution_value)
|
||||
return super(InstanceArguments, self).get_executed_params_and_issues(execution_context)
|
||||
|
||||
@@ -97,18 +97,18 @@ class GeneratorBase(LazyAttributeOverwrite, IterableMixin):
|
||||
|
||||
class Generator(GeneratorBase):
|
||||
"""Handling of `yield` functions."""
|
||||
def __init__(self, inference_state, func_execution_value):
|
||||
def __init__(self, inference_state, func_execution_context):
|
||||
super(Generator, self).__init__(inference_state)
|
||||
self._func_execution_value = func_execution_value
|
||||
self._func_execution_context = func_execution_context
|
||||
|
||||
def py__iter__(self, valueualized_node=None):
|
||||
return self._func_execution_value.get_yield_lazy_values()
|
||||
return self._func_execution_context.get_yield_lazy_values()
|
||||
|
||||
def py__stop_iteration_returns(self):
|
||||
return self._func_execution_value.get_return_values()
|
||||
return self._func_execution_context.get_return_values()
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s of %s>" % (type(self).__name__, self._func_execution_value)
|
||||
return "<%s of %s>" % (type(self).__name__, self._func_execution_context)
|
||||
|
||||
|
||||
class CompForValue(TreeValue):
|
||||
|
||||
Reference in New Issue
Block a user