def _map_rtn(args, keywords, starargs, context, dryrun, orig_args): assert not keywords assert not starargs f = args[0] elts = [] for a in args[1:]: elts.append(get_iter_type(a, context)) r = context.get_cached(_map_rtn) if not r: r = InstanceType(ListClass, [Union.EMPTY]) context.set_cached(_map_rtn, r) u = f.call(elts, {}, None, context, dryrun, orig_args) r.update(0, u) return Union(r)
def _reduce_rtn(args, keywords, starargs, context, dryrun, orig_args): assert not keywords assert not starargs assert len(args) == 3, args f, l, initial = args elt_type = get_iter_type(l, context) cur = initial MAX_TRIES = 10 for i in xrange(MAX_TRIES): next = f.call([cur, elt_type], {}, None, context, dryrun, orig_args) if next == cur: return next cur = next else: return Union(TOP)
def _filter_rtn(args, keywords, starargs, context, dryrun, orig_args): assert not keywords assert not starargs assert len(args) == 2 f = args[0] r = context.get_cached(_filter_rtn) if not r: r = InstanceType(ListClass, [Union.EMPTY]) context.set_cached(_filter_rtn, r) rtn = [] for t in args[1].types(): elt_type = get_iter_type(Union(t), context) if f != Union(NONE): f.call([elt_type], {}, None, context, dryrun, orig_args) if t is STR: rtn.append(Union(STR)) else: r.update(0, elt_type) rtn.append(Union(r)) return Union.make_union(*rtn)