示例#1
0
    def test_is_basetype(self):
        true = self.assertTrue
        true( int_t.is_base() )
        true( float_t.is_base() )
        true( str_t.is_base() )
        true( unicode_t.is_base() )
        true( bool_t.is_base() )
        true( unit_t.is_base() )

        equal = self.assertEqual
        equal( PType.int(), int_t )
        equal( PType.float(), float_t )
        equal( PType.string(), str_t )
        equal( PType.unicode(), unicode_t )
        equal( PType.bool(), bool_t )
        equal( PType.unit(), unit_t )
        all(equal(PType.from_str(k), v) for (k,v) in base_ts.iteritems())
示例#2
0
文件: util.py 项目: jruberg/Pyty
def valid_int_slice(l, u, s, env):
    """
    Determine if three AST expr nodes representing the parameters to a simple
    slice are valid integers (or Nones) under type environment `env`.

    `l`: AST expr node representing lower bound of slice.
    `u`: AST expr node representing upper bound of slice.
    `s`: AST expr node representing step of slice.
    `n`: (int) length of the collection being sliced.
    """

    # These are imported here because we don't want to pollute the entire util
    # module with potential circular references. In theory, util.py functions
    # shouldn't need to refer to checking or inferring, but this is a function
    # that happens to be shared between typecheck.py and infer.py.
    from check import check_expr
    from ptype import PType

    int_t = PType.int()

    return ((l is None or check_expr(l, int_t, env))
            and (u is None or check_expr(u, int_t, env))
            and (s is None or node_is_None(s) or check_expr(s, int_t, env)))
示例#3
0
import sys
import unittest
from lepl import sexpr_to_tree

# Include src in the Python search path
sys.path.insert(0, '../src')

from ptype import (PType, TypeSpecParser, better_sexpr_to_tree, Lst, Stt, Tup,
                   Mpp, Arr)

int_t = PType.int()
float_t = PType.float()
str_t = PType.string()
unicode_t = PType.unicode()
bool_t = PType.bool()
unit_t = PType.unit()

base_ts = {"int": int_t, "float": float_t, "str": str_t, "unicode": unicode_t,
           "bool": bool_t, "unit": unit_t}

class PTypeTests(unittest.TestCase):

    def test_is_basetype(self):
        true = self.assertTrue
        true( int_t.is_base() )
        true( float_t.is_base() )
        true( str_t.is_base() )
        true( unicode_t.is_base() )
        true( bool_t.is_base() )
        true( unit_t.is_base() )
示例#4
0
import ast
import logging

from util import cname, slice_range, node_is_int, valid_int_slice
from errors import TypeUnspecifiedError
from ptype import PType
from settings import DEBUG_INFER

# Need to use this form to resolve circular import.
import check

int_t = PType.int()
float_t = PType.float()
bool_t = PType.bool()
str_t = PType.string()
unicode_t = PType.unicode()
unit_t = PType.unit()

log = None


def i_debug(s, cond=True):
    log.debug(s, DEBUG_INFER and cond)


def call_function(fun_name, *args, **kwargs):
    return globals()[fun_name](*args, **kwargs)


def env_get(env, var_id):
    """