From 63b6fa1416793a91720a3b70f47f8089f69ebba7 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 3 Nov 2016 09:43:24 +0100 Subject: [PATCH] All function tests are passing, yay! --- jedi/evaluate/dynamic.py | 20 ++++++++++++-------- jedi/evaluate/param.py | 22 +++++++++++++++++----- jedi/evaluate/representation.py | 2 +- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/jedi/evaluate/dynamic.py b/jedi/evaluate/dynamic.py index c68202ba..8fac3ece 100644 --- a/jedi/evaluate/dynamic.py +++ b/jedi/evaluate/dynamic.py @@ -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: diff --git a/jedi/evaluate/param.py b/jedi/evaluate/param.py index 546aa1a7..79a9c0c2 100644 --- a/jedi/evaluate/param.py +++ b/jedi/evaluate/param.py @@ -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) diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index d4615c3f..236880dd 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -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):