diff --git a/jedi/evaluate/context/function.py b/jedi/evaluate/context/function.py index c9735a3d..bbfa752d 100644 --- a/jedi/evaluate/context/function.py +++ b/jedi/evaluate/context/function.py @@ -328,13 +328,16 @@ def signature_matches(function_context, arguments): key, argument = next(unpacked_arguments, (None, None)) if argument is None: # This signature has an parameter more than arguments were given. - return False + return bool(param_node.star_count) if key is not None: # TODO this is obviously wrong, we cannot just ignore keyword # arguments, but it's easier for now. return False 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( function_context.parent_context, param_node.annotation diff --git a/jedi/evaluate/context/instance.py b/jedi/evaluate/context/instance.py index 957364c9..bbc538b1 100644 --- a/jedi/evaluate/context/instance.py +++ b/jedi/evaluate/context/instance.py @@ -487,31 +487,31 @@ class SelfAttributeFilter(ClassFilter): class InstanceArguments(AbstractArguments): - def __init__(self, instance, var_args): + def __init__(self, instance, arguments): self.instance = instance - self._var_args = var_args + self._arguments = arguments @property def argument_node(self): - return self._var_args.argument_node + return self._arguments.argument_node @property def trailer(self): - return self._var_args.trailer + return self._arguments.trailer def unpack(self, func=None): yield None, LazyKnownContext(self.instance) - for values in self._var_args.unpack(func): + for values in self._arguments.unpack(func): yield values 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): - if isinstance(self._var_args, AnonymousInstanceArguments): - return self._var_args.get_executed_params(execution_context) + if isinstance(self._arguments, AnonymousInstanceArguments): + return self._arguments.get_executed_params(execution_context) return super(InstanceArguments, self).get_executed_params(execution_context) def __repr__(self): - return '<%s: %s>' % (self.__class__.__name__, self._var_args) + return '<%s: %s>' % (self.__class__.__name__, self._arguments) diff --git a/jedi/evaluate/context/iterable.py b/jedi/evaluate/context/iterable.py index 0090676c..4064d59b 100644 --- a/jedi/evaluate/context/iterable.py +++ b/jedi/evaluate/context/iterable.py @@ -208,15 +208,19 @@ class Sequence(BuiltinOverwrite, IterableMixin): assert "Should never land here, probably an issue with typeshed changes" def _get_init_functions(self, instance): - from jedi.evaluate.context.function import OverloadedFunctionContext from jedi.evaluate import arguments + from jedi.evaluate.context.instance import InstanceArguments for init in instance.py__getattribute__('__init__'): try: method = init.get_matching_functions except AttributeError: continue else: - for x in method(arguments.ValuesArguments([ContextSet(self)])): + arguments = InstanceArguments( + instance, + arguments.ValuesArguments([ContextSet(self)]) + ) + for x in method(arguments): yield x def py__bool__(self): diff --git a/jedi/evaluate/context/klass.py b/jedi/evaluate/context/klass.py index 05d3b736..ec818dfe 100644 --- a/jedi/evaluate/context/klass.py +++ b/jedi/evaluate/context/klass.py @@ -179,7 +179,10 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)): continue # These are not relevant for this search. 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 @evaluator_method_cache(default=()) diff --git a/jedi/evaluate/context/typing.py b/jedi/evaluate/context/typing.py index 40b97a09..d23d48d4 100644 --- a/jedi/evaluate/context/typing.py +++ b/jedi/evaluate/context/typing.py @@ -506,9 +506,9 @@ class _AbstractAnnotatedClass(ClassContext): if self.tree_node != other.tree_node: # TODO not sure if this is nice. return False - given_params1 = self.get_given_types() given_params2 = other.get_given_types() + if len(given_params1) != len(given_params2): # If the amount of type vars doesn't match, the class doesn't # match. diff --git a/jedi/evaluate/pep0484.py b/jedi/evaluate/pep0484.py index 42146310..69474bfe 100644 --- a/jedi/evaluate/pep0484.py +++ b/jedi/evaluate/pep0484.py @@ -21,7 +21,6 @@ x support for type hint comments for functions, `# type: (int, str) -> int`. import os import re -from collections import OrderedDict from parso import ParserSyntaxError, parse, split_lines from parso.python import tree @@ -178,7 +177,7 @@ def infer_param(execution_context, param): def py__annotations__(funcdef): - dct = OrderedDict() + dct = {} for function_param in funcdef.get_params(): param_annotation = function_param.annotation if param_annotation is not None: @@ -456,10 +455,10 @@ def find_unknown_type_vars(context, node): else: type_var_set = context.eval_node(node) for type_var in type_var_set: - if isinstance(type_var, TypeVar): - found.add(type_var) + if isinstance(type_var, TypeVar) and type_var not in found: + found.append(type_var) - found = set() + found = [] # We're not using a set, because the order matters. check_node(node) return found