From 4bb7a595e874b1fa1c644400ee09849ed95f484f Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 25 Sep 2018 23:05:23 +0200 Subject: [PATCH] Fix some issues with signature matching --- jedi/evaluate/param.py | 12 ++++++++++-- test/completion/stdlib.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/jedi/evaluate/param.py b/jedi/evaluate/param.py index 23a4190b..d00e8116 100644 --- a/jedi/evaluate/param.py +++ b/jedi/evaluate/param.py @@ -18,11 +18,12 @@ def _add_argument_issue(parent_context, error_name, lazy_context, message): class ExecutedParam(object): """Fake a param and give it values.""" - def __init__(self, execution_context, param_node, lazy_context): + def __init__(self, execution_context, param_node, lazy_context, is_default=False): self._execution_context = execution_context self._param_node = param_node self._lazy_context = lazy_context self.string_name = param_node.name.value + self._is_default = is_default def infer_annotations(self): from jedi.evaluate import pep0484 @@ -38,6 +39,8 @@ class ExecutedParam(object): return self._lazy_context.infer() def matches_signature(self): + if self._is_default: + return True argument_contexts = self.infer(use_hints=False).py__class__() if self._param_node.star_count: return True @@ -99,6 +102,7 @@ def get_executed_params_and_issues(execution_context, 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. + is_default = False key, argument = next(var_arg_iterator, (None, None)) while key is not None: keys_only = True @@ -165,10 +169,14 @@ def get_executed_params_and_issues(execution_context, var_args): ) else: result_arg = LazyTreeContext(default_param_context, param.default) + is_default = True else: result_arg = argument - result_params.append(ExecutedParam(execution_context, param, result_arg)) + result_params.append(ExecutedParam( + execution_context, param, result_arg, + is_default=is_default + )) if not isinstance(result_arg, LazyUnknownContext): keys_used[param.name.value] = result_params[-1] diff --git a/test/completion/stdlib.py b/test/completion/stdlib.py index 8072138e..69b17ee2 100644 --- a/test/completion/stdlib.py +++ b/test/completion/stdlib.py @@ -72,7 +72,7 @@ if os.path.isfile(): with open('foo') as f: for line in f.readlines(): - #? str() + #? str() bytes() line # ----------------- # enumerate