mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-30 20:35:23 +08:00
All function tests are passing, yay!
This commit is contained in:
@@ -24,8 +24,9 @@ from jedi import settings
|
||||
from jedi import debug
|
||||
from jedi.evaluate.cache import memoize_default
|
||||
from jedi.evaluate import imports
|
||||
from jedi.evaluate.param import TreeArguments
|
||||
from jedi.evaluate.param import TreeArguments, create_default_param
|
||||
from jedi.common import to_list, unite
|
||||
from jedi.evaluate import context
|
||||
|
||||
|
||||
MAX_PARAM_SEARCHES = 20
|
||||
@@ -54,7 +55,7 @@ class MergedExecutedParams(object):
|
||||
|
||||
|
||||
@debug.increase_indent
|
||||
def search_params(evaluator, funcdef):
|
||||
def search_params(evaluator, parent_context, funcdef):
|
||||
"""
|
||||
A dynamic search for param values. If you try to complete a type:
|
||||
|
||||
@@ -74,12 +75,15 @@ def search_params(evaluator, funcdef):
|
||||
try:
|
||||
debug.dbg('Dynamic param search in %s.', funcdef.name.value, color='MAGENTA')
|
||||
function_executions = _search_function_executions(evaluator, funcdef)
|
||||
zipped_params = zip(*(
|
||||
function_execution.get_params()
|
||||
for function_execution in function_executions
|
||||
))
|
||||
params = [MergedExecutedParams(executed_params) for executed_params in zipped_params]
|
||||
# Evaluate the ExecutedParams to types.
|
||||
if function_executions:
|
||||
zipped_params = zip(*(
|
||||
function_execution.get_params()
|
||||
for function_execution in function_executions
|
||||
))
|
||||
params = [MergedExecutedParams(executed_params) for executed_params in zipped_params]
|
||||
# Evaluate the ExecutedParams to types.
|
||||
else:
|
||||
params = [create_default_param(parent_context, p) for p in funcdef.params]
|
||||
debug.dbg('Dynamic param result finished', color='MAGENTA')
|
||||
return params
|
||||
finally:
|
||||
|
||||
@@ -259,11 +259,7 @@ def get_params(evaluator, parent_context, func, var_args):
|
||||
# args / kwargs will just be empty arrays / dicts, respectively.
|
||||
# Wrong value count is just ignored. If you try to test cases that are
|
||||
# not allowed in Python, Jedi will maybe not show any completions.
|
||||
default = None
|
||||
if param.default is not None:
|
||||
default = context.LazyTreeContext(parent_context, param.default)
|
||||
|
||||
key, argument = next(var_arg_iterator, (None, default))
|
||||
key, argument = next(var_arg_iterator, (None, None))
|
||||
while key is not None:
|
||||
keys_only = True
|
||||
try:
|
||||
@@ -415,3 +411,19 @@ def _error_argument_count(func, actual_count):
|
||||
before = 'from %s to ' % (len(func.params) - default_arguments)
|
||||
return ('TypeError: %s() takes %s%s arguments (%s given).'
|
||||
% (func.name, before, len(func.params), actual_count))
|
||||
|
||||
|
||||
def create_default_param(parent_context, param):
|
||||
if param.stars == 1:
|
||||
result_arg = context.LazyKnownContext(
|
||||
iterable.FakeSequence(parent_context._evaluator, 'tuple', [])
|
||||
)
|
||||
elif param.stars == 2:
|
||||
result_arg = context.LazyKnownContext(
|
||||
iterable.FakeDict(parent_context._evaluator, {})
|
||||
)
|
||||
elif param.default is None:
|
||||
result_arg = context.LazyUnknownContext()
|
||||
else:
|
||||
result_arg = context.LazyTreeContext(parent_context, param.default)
|
||||
return ExecutedParam(param, None, result_arg)
|
||||
|
||||
@@ -719,7 +719,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.funcdef)
|
||||
return search_params(self._evaluator, self.parent_context, self.funcdef)
|
||||
|
||||
|
||||
class GlobalName(helpers.FakeName):
|
||||
|
||||
Reference in New Issue
Block a user