How to use the pythran.types.tog.Collection function in pythran

To help you get started, we’ve selected a few pythran examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
def Tuple(of_types):
    return Collection(Traits([TupleTrait(of_types), LenTrait, SliceTrait]),
                      Integer(), TypeVariable(), TypeVariable())
github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
def Float():
    return Collection(Traits([ArrayTrait, NoLenTrait, NoSliceTrait]),
                      InvalidKey, Scalar('float'), InvalidKey)
github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
def Str(rec=6):
    Next = Str(rec - 1) if rec else TypeVariable()
    return Collection(Traits([StrTrait, LenTrait, SliceTrait]),
                      Integer(),
                      Next,
                      Next)
github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
def File():
    return Collection(Traits([FileTrait, NoLenTrait, NoSliceTrait]),
                      InvalidKey, Str(), Str())
github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
def Array(of_type, dim):
    return Collection(Traits([ArrayTrait, LenTrait, SliceTrait]),
                      AnyType,
                      AnyType,
                      Array(of_type, dim - 1) if dim > 1 else of_type)
github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
if '@ret' in env:
            try:
                ret_type = merge_unify(env['@ret'], ret_type)
            except InferenceError:
                raise PythranTypeError(
                    "function may yields incompatible types "
                    "`{}` and `{}`".format(env['@ret'], ret_type),
                    node
                )

        env['@ret'] = ret_type
        return env
    elif isinstance(node, gast.For):
        iter_type = analyse(node.iter, env, non_generic)
        target_type = analyse(node.target, env, non_generic)
        unify(Collection(TypeVariable(), TypeVariable(), TypeVariable(),
                         target_type),
              iter_type)
        analyse_body(node.body, env, non_generic)
        analyse_body(node.orelse, env, non_generic)
        return env
    elif isinstance(node, gast.If):
        test_type = analyse(node.test, env, non_generic)
        unify(Function([test_type], Bool()),
              tr(MODULES['__builtin__']['bool']))

        body_env = env.copy()
        body_non_generic = non_generic.copy()

        if is_test_is_none(node.test):
            none_id = node.test.left.id
            body_env[none_id] = NoneType
github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
def Integer():
    return Collection(Traits([ArrayTrait, NoLenTrait, NoSliceTrait]),
                      InvalidKey, Scalar('int'), InvalidKey)
github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
def Generator(of_type):
    return Collection(Traits([GenerableTrait, NoLenTrait, NoSliceTrait]),
                      InvalidKey, of_type, of_type)
github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
def Set(of_type):
    return Collection(Traits([SetTrait, LenTrait, NoSliceTrait]),
                      InvalidKey, of_type, of_type)
github serge-sans-paille / pythran / pythran / types / tog.py View on Github external
if haslen:
                            t, n = rec(pn.types[3])
                            return t, n + 1
                        # a scalar or array?
                        else:
                            return pn.types[2], 0
                    else:
                        return pn, 0
                t, n = rec(self)
                if isinstance(t, TypeVariable):
                    return 'Array[{} d+, {}]'.format(n, t)
                else:
                    return 'Array[{}d, {}]'.format(n, t)
            if type_trait == 'gen':
                return 'Generator[{}]'.format(self.types[2])
        return super(Collection, self).__str__()