1
0
forked from VimPlug/jedi

Fix some signature matching for methods

This commit is contained in:
Dave Halter
2018-09-18 23:48:26 +02:00
parent 1b11162132
commit 57fa5f5bd9
6 changed files with 28 additions and 19 deletions

View File

@@ -328,13 +328,16 @@ def signature_matches(function_context, arguments):
key, argument = next(unpacked_arguments, (None, None)) key, argument = next(unpacked_arguments, (None, None))
if argument is None: if argument is None:
# This signature has an parameter more than arguments were given. # This signature has an parameter more than arguments were given.
return False return bool(param_node.star_count)
if key is not None: if key is not None:
# TODO this is obviously wrong, we cannot just ignore keyword # TODO this is obviously wrong, we cannot just ignore keyword
# arguments, but it's easier for now. # arguments, but it's easier for now.
return False return False
if param_node.annotation is not None: if param_node.annotation is not None:
if param_node.star_count == 2:
return False # TODO allow this
annotation_contexts = function_context.evaluator.eval_element( annotation_contexts = function_context.evaluator.eval_element(
function_context.parent_context, function_context.parent_context,
param_node.annotation param_node.annotation

View File

@@ -487,31 +487,31 @@ class SelfAttributeFilter(ClassFilter):
class InstanceArguments(AbstractArguments): class InstanceArguments(AbstractArguments):
def __init__(self, instance, var_args): def __init__(self, instance, arguments):
self.instance = instance self.instance = instance
self._var_args = var_args self._arguments = arguments
@property @property
def argument_node(self): def argument_node(self):
return self._var_args.argument_node return self._arguments.argument_node
@property @property
def trailer(self): def trailer(self):
return self._var_args.trailer return self._arguments.trailer
def unpack(self, func=None): def unpack(self, func=None):
yield None, LazyKnownContext(self.instance) yield None, LazyKnownContext(self.instance)
for values in self._var_args.unpack(func): for values in self._arguments.unpack(func):
yield values yield values
def get_calling_nodes(self): def get_calling_nodes(self):
return self._var_args.get_calling_nodes() return self._arguments.get_calling_nodes()
def get_executed_params(self, execution_context): def get_executed_params(self, execution_context):
if isinstance(self._var_args, AnonymousInstanceArguments): if isinstance(self._arguments, AnonymousInstanceArguments):
return self._var_args.get_executed_params(execution_context) return self._arguments.get_executed_params(execution_context)
return super(InstanceArguments, self).get_executed_params(execution_context) return super(InstanceArguments, self).get_executed_params(execution_context)
def __repr__(self): def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self._var_args) return '<%s: %s>' % (self.__class__.__name__, self._arguments)

View File

@@ -208,15 +208,19 @@ class Sequence(BuiltinOverwrite, IterableMixin):
assert "Should never land here, probably an issue with typeshed changes" assert "Should never land here, probably an issue with typeshed changes"
def _get_init_functions(self, instance): def _get_init_functions(self, instance):
from jedi.evaluate.context.function import OverloadedFunctionContext
from jedi.evaluate import arguments from jedi.evaluate import arguments
from jedi.evaluate.context.instance import InstanceArguments
for init in instance.py__getattribute__('__init__'): for init in instance.py__getattribute__('__init__'):
try: try:
method = init.get_matching_functions method = init.get_matching_functions
except AttributeError: except AttributeError:
continue continue
else: else:
for x in method(arguments.ValuesArguments([ContextSet(self)])): arguments = InstanceArguments(
instance,
arguments.ValuesArguments([ContextSet(self)])
)
for x in method(arguments):
yield x yield x
def py__bool__(self): def py__bool__(self):

View File

@@ -179,7 +179,10 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
continue # These are not relevant for this search. continue # These are not relevant for this search.
from jedi.evaluate.pep0484 import find_unknown_type_vars from jedi.evaluate.pep0484 import find_unknown_type_vars
found += find_unknown_type_vars(self.parent_context, node) for type_var in find_unknown_type_vars(self.parent_context, node):
if type_var not in found:
# The order matters and it's therefore a list.
found.append(type_var)
return found return found
@evaluator_method_cache(default=()) @evaluator_method_cache(default=())

View File

@@ -506,9 +506,9 @@ class _AbstractAnnotatedClass(ClassContext):
if self.tree_node != other.tree_node: if self.tree_node != other.tree_node:
# TODO not sure if this is nice. # TODO not sure if this is nice.
return False return False
given_params1 = self.get_given_types() given_params1 = self.get_given_types()
given_params2 = other.get_given_types() given_params2 = other.get_given_types()
if len(given_params1) != len(given_params2): if len(given_params1) != len(given_params2):
# If the amount of type vars doesn't match, the class doesn't # If the amount of type vars doesn't match, the class doesn't
# match. # match.

View File

@@ -21,7 +21,6 @@ x support for type hint comments for functions, `# type: (int, str) -> int`.
import os import os
import re import re
from collections import OrderedDict
from parso import ParserSyntaxError, parse, split_lines from parso import ParserSyntaxError, parse, split_lines
from parso.python import tree from parso.python import tree
@@ -178,7 +177,7 @@ def infer_param(execution_context, param):
def py__annotations__(funcdef): def py__annotations__(funcdef):
dct = OrderedDict() dct = {}
for function_param in funcdef.get_params(): for function_param in funcdef.get_params():
param_annotation = function_param.annotation param_annotation = function_param.annotation
if param_annotation is not None: if param_annotation is not None:
@@ -456,10 +455,10 @@ def find_unknown_type_vars(context, node):
else: else:
type_var_set = context.eval_node(node) type_var_set = context.eval_node(node)
for type_var in type_var_set: for type_var in type_var_set:
if isinstance(type_var, TypeVar): if isinstance(type_var, TypeVar) and type_var not in found:
found.add(type_var) found.append(type_var)
found = set() found = [] # We're not using a set, because the order matters.
check_node(node) check_node(node)
return found return found