def UnCurry(func, num_args__s, /): check_callable(func) check_type_is(tuple, num_args__s) any(map(check_uint, num_args__s)) if not num_args__s: data = func return data elif len(num_args__s) == 1: return func num_args4call__total = 1 + sum(num_args__s) # 1 -- first arg _0 is "func" itself uXss4body = 0 # _0 := func begin = 1 # [_1..] for num_args4call in num_args__s: end = begin + num_args4call uXss4body = (uXss4body, *range(begin, end)) begin = end assert begin == end == num_args4call__total g = mk_CurriedFreeLocalBatchRouter4py([1, num_args4call__total - 1], uXss4body, [[func]]) if __debug__: f_ = FreeLocalBatchRouter4py(num_args4call__total, uXss4body) f = Curry(f_, ((), (func, )), (num_args4call__total - 1, ())) assert g.get_args8init_Curry() == f.get_args8init_Curry() return g
def split_at(n, rope, /): '-> (initial_seq, tail_rope)' check_uint(n) check_type_is(tuple, rope) if n == 0: return (), rope size = rope[0] if not 0 <= n <= size: raise ValueError N = n L = size lss = [] while n > 0: (size, num_skips, seq, rope) = rope end = num_skips + n ls = seq[num_skips:end] lss.append(ls) n -= len(ls) if not n == 0: raise logic - err #bug:tail_rope = RopeOps.mk(num_skips+n, seq, rope) tail_rope = mk(end, seq, rope) it = itertools.chain.from_iterable(lss) initial_seq = (*it, ) assert len(initial_seq) == N assert L == N + tail_rope[0] return initial_seq, tail_rope
def __init__(sf, func, args_rglnkls, num_args_lflnkls, /): check_callable(func) check_type_is(tuple, args_rglnkls) check_type_is(tuple, num_args_lflnkls) assert len(args_rglnkls) in [0, 2] #assert len(num_args_lflnkls) in [0,2] if not num_args_lflnkls: raise TypeError sf._func = func sf._args_rglnkls = args_rglnkls sf._num_args_lflnkls = num_args_lflnkls return
def get_PermanentSymbol(module_qname4extensional_path, smay_holder_object_qname4extensional_path, symbol_qname4extensional_path, /): '-> PermanentSymbol|raise ImportError/AttributeError' holder_vs_symbol = _get_either_holder_vs_symbol( module_qname4extensional_path, smay_holder_object_qname4extensional_path, symbol_qname4extensional_path) if not symbol_qname4extensional_path: raise TypeError symbol = holder_vs_symbol check_type_is(PermanentSymbol, symbol) return symbol
def _iter_(rope, /): check_type_is(tuple, rope) n = _len_(rope) while not rope is None: #(size, num_skips, seq, may_rope) = rope (size, num_skips, seq, rope) = rope assert n == size ls = seq[num_skips:] yield from ls n -= len(ls) if not n == 0: raise logic - err return #
def __init__(sf, func, args_rglnkls, num_remain_args, num_remain_tail_laziness, /): check_callable(func) check_type_is(tuple, args_rglnkls) check_uint(num_remain_args) check_uint(num_remain_tail_laziness) assert len(args_rglnkls) in [0, 2] if not (num_remain_args or num_remain_tail_laziness): raise TypeError sf._func = func sf._args_rglnkls = args_rglnkls sf._num_remain_args = num_remain_args sf._num_remain_tail_laziness = num_remain_tail_laziness return
def mk2(num_skips, seq, rope, /): h_rope = mk1(num_skips, seq) # check and get size check_type_is(tuple, rope) if not len(rope) == 4: raise TypeError sz0 = h_rope[0] #RopeOps._len_ if sz0 == 0: return rope sz1 = rope[0] #RopeOps._len_ if sz1 == 0: return h_rope size = sz0 + sz1 return (size, num_skips, seq, rope)
def __call__(sf, f, /): cls = type(sf) ___main_attr___ = cls.___main_attr___ if not hasattr(f, ___main_attr___): setattr(f, ___main_attr___, {}) lord2arged_opts = getattr(f, ___main_attr___) lord = sf.get_symbol8lord() arged_opts = lord2arged_opts.setdefault(lord, []) case4option = sf.get_case4option() args4case = sf.get_args4case() arged_opt = case4option, args4case check_type_is(tuple, args4case) sf.check_args4case(*args4case) arged_opts.append(arged_opt) return f
def _initial_of_relay(initial_cls4mro, may_mro_idx4middle_relay_cls, may_middle_relay_cls, offset4restart_from_middle: int, /): check_type_is(int, offset4restart_from_middle) mro = initial_cls4mro.__mro__ check_type_is(tuple, mro) assert mro if may_mro_idx4middle_relay_cls is None is may_middle_relay_cls: mro_idx4middle_relay_cls = 0 middle_relay_cls = mro[0] else: if may_middle_relay_cls is None: mro_idx4middle_relay_cls = may_mro_idx4middle_relay_cls check_type_is(int, mro_idx4middle_relay_cls) middle_relay_cls = mro[mro_idx4middle_relay_cls] else: middle_relay_cls = may_middle_relay_cls if may_mro_idx4middle_relay_cls is None: mro_idx4middle_relay_cls = mro.index(middle_relay_cls) else: mro_idx4middle_relay_cls = may_mro_idx4middle_relay_cls mro_idx4middle_relay_cls middle_relay_cls check_type_is(int, mro_idx4middle_relay_cls) if not 0 <= mro_idx4middle_relay_cls < len(mro): raise TypeError # < if not mro[mro_idx4middle_relay_cls] is middle_relay_cls: raise TypeError ###################################### ###################################### restart_idx4mro = mro_idx4middle_relay_cls + offset4restart_from_middle if not 0 <= restart_idx4mro <= len(mro): raise TypeError # <= return mro_idx4middle_relay_cls, middle_relay_cls, restart_idx4mro
def i2v(i, /): check_type_is(int, i) v = sf.__s[i] return sf.__cfg.to_view(v)