Beispiel #1
0
 def _break_constant(self, const, loc):
     """
     Break down constant exception.
     """
     if isinstance(const, tuple):  # it's a tuple(exception class, args)
         if not self._is_exception_type(const[0]):
             msg = "Encountered unsupported exception constant %r"
             raise errors.UnsupportedError(msg % (const[0], ), loc)
         return const[0], tuple(const[1])
     elif self._is_exception_type(const):
         return const, None
     else:
         if isinstance(const, str):
             msg = ("Directly raising a string constant as an exception is "
                    "not supported.")
         else:
             msg = "Encountered unsupported constant type used for exception"
         raise errors.UnsupportedError(msg, loc)
Beispiel #2
0
def _getargs(fn_sig):
    """
    Returns list of positional and keyword argument names in order.
    """
    params = fn_sig.parameters
    args = []
    for k, v in params.items():
        if (v.kind & v.POSITIONAL_OR_KEYWORD) == v.POSITIONAL_OR_KEYWORD:
            args.append(k)
        else:
            msg = "%s argument type unsupported in jitclass" % v.kind
            raise errors.UnsupportedError(msg)
    return args
Beispiel #3
0
def exception_match(typingctx, exc_value, exc_class):
    """Basically do ``isinstance(exc_value, exc_class)`` for exception objects.
    Used in ``except Exception:`` syntax.
    """
    # Check for our limitation
    if exc_class.exc_class is not Exception:
        msg = "Exception matching is limited to {}"
        raise errors.UnsupportedError(msg.format(Exception))

    def codegen(context, builder, signature, args):
        # Intentionally always True.
        return cgutils.true_bit

    restype = types.boolean
    return restype(exc_value, exc_class), codegen
Beispiel #4
0
 def match(self, func_ir, block, typemap, calltypes):
     self.prints = prints = {}
     self.block = block
     # Find all assignments with a right-hand print() call
     for inst in block.find_insts(ir.Assign):
         if isinstance(inst.value, ir.Expr) and inst.value.op == 'call':
             expr = inst.value
             try:
                 callee = func_ir.infer_constant(expr.func)
             except errors.ConstantInferenceError:
                 continue
             if callee is print:
                 if expr.kws:
                     # Only positional args are supported
                     msg = ("Numba's print() function implementation does not "
                         "support keyword arguments.")
                     raise errors.UnsupportedError(msg, inst.loc)
                 prints[inst] = expr
     return len(prints) > 0