Esempio n. 1
0
def arg_check(expected_type, args, a):
    if expected_type != args['pseudo_type'] and expected_type != 'Any' and not (
            expected_type == 'Number' and
        (args['pseudo_type'] == 'int' or args['pseudo_type'] == 'float')):
        raise PseudoCythonTypeCheckError('%s expected %s not %s' %
                                         (a, serialize_type(expected_type),
                                          serialize_type(args['pseudo_type'])))
Esempio n. 2
0
def or_(l, r):
    if l == 'bool' and r == 'bool':
        return 'bool'
    else:
        raise PseudoCythonTypeCheckError(
            "wrong types for or: %s and %s" %
            (serialize_type(l), serialize_type(r)))
Esempio n. 3
0
def binary_or(l, r):
    if l == r == 'int' or l == r == 'Set':
        return l
    else:
        raise PseudoCythonTypeCheckError(
            "wrong types for |: %s and %s" %
            (serialize_type(l), serialize_type(r)))
Esempio n. 4
0
def mod(l, r):
    if l == 'int' and r == 'int':
        return [l, r, 'int']
    elif l == 'str' and (r == 'str' or r == ['array', 'str']):
        return [l, ['array', 'str'], 'str']
    else:
        raise PseudoCythonTypeCheckError(
            "wrong types for modulo : %s and %s" %
            (serialize_type(l), serialize_type(r)))
Esempio n. 5
0
def pow_(l, r):
    if l == 'float' and r in ['float', 'int'
                              ] or r == 'float' and l in ['float', 'int']:
        return [l, r, 'float']
    elif l == 'int' and r == 'int':
        return [l, r, 'int']
    elif l == "unknown" or r == "unknown":
        return [l, r, "unknown"]
    else:
        raise PseudoCythonTypeCheckError(
            "wrong types for **: %s and %s" %
            (serialize_type(l), serialize_type(r)))
Esempio n. 6
0
def div(l, r, lo=None):
    if l == 'float' and r in ['float', 'int'
                              ] or r == 'float' and l in ['float', 'int']:
        return [l, r, 'float']
    elif l == 'int' and r == 'int':
        return [l, r, 'int']
        #raise PseudoCythonTypeCheckError("cast one variable at line %s position %s between /: %s and %s" % (lo[0], lo[1], serialize_type(l), serialize_type(r)))
    elif l == "unknown" or r == "unknown":
        return [l, r, "unknown"]
    else:
        raise PseudoCythonTypeCheckError(
            "wrong types for /: %s and %s" %
            (serialize_type(l), serialize_type(r)))
Esempio n. 7
0
def mul(l, r):
    if l == 'float' and r in ['float', 'int'
                              ] or r == 'float' and l in ['float', 'int']:
        return [l, r, 'float']
    elif l == 'int' and r == 'int':
        return [l, r, 'int']
    elif l == 'int' and (isinstance(r, list) and r[0] == 'list' or r == 'str'):
        return [l, r, r]
    elif r == 'int' and (isinstance(l, list) and l[0] == 'list' or l == 'str'):
        return [l, r, l]
    elif l == "unknown" or r == "unknown":
        return [l, r, "unknown"]
    else:
        raise PseudoCythonTypeCheckError(
            "wrong types for *: %s and %s" %
            (serialize_type(l), serialize_type(r)))
Esempio n. 8
0
 def decorated(data,
               location=None,
               code=None,
               wrong_type=None,
               **options):
     return exception(
         '%s%s%s:\n%s\n%s^' %
         (('wrong type %s\n' %
           serialize_type(wrong_type) if wrong_type else ''), data,
          (' on line %d column %d' % location) if location else '', code
          or '', (tab_aware(location[1], code) if location else '')),
         **options)