pyrser/type_system/scope.py
def get_by_params(self, params: [Scope]) -> (Scope, [[Scope]]):
        """ Retrieve a Set of all signature that match the parameter list.
        Return a pair:

            pair[0] the overloads for the functions
            pair[1] the overloads for the parameters
                (a list of candidate list of parameters)
        """
        lst = []
        scopep = []
        # for each of our signatures
        for s in self.values():
            # for each params of this signature
            if hasattr(s, 'tparams'):
                # number of matched params
                mcnt = 0
                # temporary collect
                nbparam_sig = (0 if s.tparams is None else len(s.tparams))
                nbparam_candidates = len(params)
                # don't treat signature too short
                if nbparam_sig > nbparam_candidates:
                    continue
                # don't treat call signature too long if not variadic
                if nbparam_candidates > nbparam_sig and not s.variadic:
                    continue
                tmp = [None] * nbparam_candidates
                variadic_types = []
                for i in range(nbparam_candidates):
                    tmp[i] = Scope(state=StateScope.LINKED)
                    tmp[i].set_parent(self)
                    # match param of the expr
                    if i < nbparam_sig:
                        if params[i].state == StateScope.EMBEDDED:
                            raise ValueError(
                                ("params[%d] of get_by_params is a StateScope."
                                 + "EMBEDDED scope... "
                                 + "read the doc and try a StateScope.FREE"
                                 + " or StateScope.LINKED.") % i
                            )
                        m = params[i].get_by_return_type(s.tparams[i])
                        if len(m) > 0:
                            mcnt += 1
                            tmp[i].update(m)
                        else:
                            # co/contra-variance
                            # we just need to search a t1->t2
                            # and add it into the tree (with/without warnings)
                            t1 = params[i]
                            t2 = s.tparams[i]
                            # if exist a fun (t1) -> t2
                            (is_convertible,
                             signature,
                             translator
                             ) = t1.findTranslationTo(t2)
                            if is_convertible:
                                # add a translator in the EvalCtx
                                signature.use_translator(translator)
                                mcnt += 1
                                nscope = Scope(
                                    sig=[signature],
                                    state=StateScope.LINKED,
                                    is_namespace=False
                                    )
                                nscope.set_parent(self)
                                tmp[i].update(nscope)
                            elif s.tparams[i].is_polymorphic:
                                # handle polymorphic parameter
                                mcnt += 1
                                if not isinstance(params[i], Scope):
                                    raise Exception(
                                        "params[%d] must be a Scope" % i
                                    )
                                tmp[i].update(params[i])
                            else:
                                # handle polymorphic return type
                                m = params[i].get_all_polymorphic_return()
                                if len(m) > 0:
                                    mcnt += 1
                                    tmp[i].update(m)
                    # for variadic extra parameters
                    else:
                        mcnt += 1
                        if not isinstance(params[i], Scope):
                            raise Exception("params[%d] must be a Scope" % i)
                        variadic_types.append(params[i].first().tret)
                        tmp[i].update(params[i])
                # we have match all candidates
                if mcnt == len(params):
                    # select this signature but
                    # box it (with EvalCtx) for type resolution
                    lst.append(EvalCtx.from_sig(s))
                    lastentry = lst[-1]
                    if lastentry.variadic:
                        lastentry.use_variadic_types(variadic_types)
                    scopep.append(tmp)
        rscope = Scope(sig=lst, state=StateScope.LINKED, is_namespace=False)
        # inherit type/translation from parent
        rscope.set_parent(self)
        return (rscope, scopep)
def get_by_params(self, params: [Scope]) -> (Scope, [[Scope]]):
        """ Retrieve a Set of all signature that match the parameter list.
        Return a pair:

            pair[0] the overloads for the functions
            pair[1] the overloads for the parameters
                (a list of candidate list of parameters)
        """
        lst = []
        scopep = []
        # for each of our signatures
        for s in self.values():
            # for each params of this signature
            if hasattr(s, 'tparams'):
                # number of matched params
                mcnt = 0
                # temporary collect
                nbparam_sig = (0 if s.tparams is None else len(s.tparams))
                nbparam_candidates = len(params)
                # don't treat signature too short
                if nbparam_sig > nbparam_candidates:
                    continue
                # don't treat call signature too long if not variadic
                if nbparam_candidates > nbparam_sig and not s.variadic:
                    continue
                tmp = [None] * nbparam_candidates
                variadic_types = []
                for i in range(nbparam_candidates):
                    tmp[i] = Scope(state=StateScope.LINKED)
                    tmp[i].set_parent(self)
                    # match param of the expr
                    if i < nbparam_sig:
                        if params[i].state == StateScope.EMBEDDED:
                            raise ValueError(
                                ("params[%d] of get_by_params is a StateScope."
                                 + "EMBEDDED scope... "
                                 + "read the doc and try a StateScope.FREE"
                                 + " or StateScope.LINKED.") % i
                            )
                        m = params[i].get_by_return_type(s.tparams[i])
                        if len(m) > 0:
                            mcnt += 1
                            tmp[i].update(m)
                        else:
                            # co/contra-variance
                            # we just need to search a t1->t2
                            # and add it into the tree (with/without warnings)
                            t1 = params[i]
                            t2 = s.tparams[i]
                            # if exist a fun (t1) -> t2
                            (is_convertible,
                             signature,
                             translator
                             ) = t1.findTranslationTo(t2)
                            if is_convertible:
                                # add a translator in the EvalCtx
                                signature.use_translator(translator)
                                mcnt += 1
                                nscope = Scope(
                                    sig=[signature],
                                    state=StateScope.LINKED,
                                    is_namespace=False
                                    )
                                nscope.set_parent(self)
                                tmp[i].update(nscope)
                            elif s.tparams[i].is_polymorphic:
                                # handle polymorphic parameter
                                mcnt += 1
                                if not isinstance(params[i], Scope):
                                    raise Exception(
                                        "params[%d] must be a Scope" % i
                                    )
                                tmp[i].update(params[i])
                            else:
                                # handle polymorphic return type
                                m = params[i].get_all_polymorphic_return()
                                if len(m) > 0:
                                    mcnt += 1
                                    tmp[i].update(m)
                    # for variadic extra parameters
                    else:
                        mcnt += 1
                        if not isinstance(params[i], Scope):
                            raise Exception("params[%d] must be a Scope" % i)
                        variadic_types.append(params[i].first().tret)
                        tmp[i].update(params[i])
                # we have match all candidates
                if mcnt == len(params):
                    # select this signature but
                    # box it (with EvalCtx) for type resolution
                    lst.append(EvalCtx.from_sig(s))
                    lastentry = lst[-1]
                    if lastentry.variadic:
                        lastentry.use_variadic_types(variadic_types)
                    scopep.append(tmp)
        rscope = Scope(sig=lst, state=StateScope.LINKED, is_namespace=False)
        # inherit type/translation from parent
        rscope.set_parent(self)
        return (rscope, scopep)
Retrieve a Set of all signature that match the parameter list.
        Return a pair:

            pair[0] the overloads for the functions
            pair[1] the overloads for the parameters
                (a list of candidate list of parameters)