def test_partial_as_callback(): func = _.partial(lambda offset, value, *args: value + offset, 5) case = [1, 2, 3] expected = [6, 7, 8] _.map_(case, func) == expected
def _method_of(path, *_args, **_kargs): func = pyd.partial(pyd.get(obj, path), *args, **kargs) return func(*_args, **_kargs)
def test_partial_as_iteratee(): func = _.partial(lambda offset, value, *args: value + offset, 5) case = [1, 2, 3] expected = [6, 7, 8] _.map_(case, func) == expected
def test_partial(case, case_args, case_kargs, args, expected): assert _.partial(case, *case_args, **case_kargs)(*args) == expected
def get_link_contexts_using_heuristics(redirects_lookup, page): return pipe(get_link_contexts(redirects_lookup, page), _.partial(_page_title_exact_match_heuristic, page), _.partial(_link_title_exact_match_heuristic, page), _drop_overlapping_mentions, _.partial(_entity_for_each_page, page))
return def __get_rev(revs, config): """ Either get a single revision, if `rev_num` is set or return all """ if config.get("rev_num") is not None: __log__.debug("Rev num set. {}".format(config.get("rev_num"))) try: if int(config.get("rev_num")) < len(revs): pos = int(config.get("rev_num")) revToUse = revs[pos] __log__.debug("Pos set. New rev is {}".format(revToUse)) except: pass else: revToUse = revs return revToUse # Maps string to a formatter function. Typically use partial funcs to config the formatters FORMATTER_MAP = {"json": _.partial(json.dumps, indent=2, sort_keys=True)} REVS_DEST_MAP = {"print": print, "pprint": pprint.pprint} if __name__ == '__main__': run(sys.argv)
def _method(obj, *_args, **_kwargs): func = pyd.partial(pyd.get(obj, path), *args, **kwargs) return func(*_args, **_kwargs)
pos = int(config.get("rev_num")) revToUse = revs[pos] __log__.debug("Pos set. New rev is {}".format(revToUse)) except Exception as err: __log__.debug("Error getting specific rev. Returing all: {}".format(err.message)) elif config.get("rev_list"): __log__.debug("Rev list set. Getting list of revs") revToUse = _.pluck(revs, "revision") else: revToUse = revs return revToUse # Maps string to a formatter function. Typically use partial funcs to config the formatters FORMATTER_MAP = { "json": _.partial(json.dumps, indent = 2, sort_keys = True), "idenity": _.identity, } REVS_OUTPUT_MAP = { "print": print, "pprint": pprint.pprint } if __name__ == '__main__': run(sys.argv)