nwo
stringlengths
10
28
sha
stringlengths
40
40
path
stringlengths
11
97
identifier
stringlengths
1
64
parameters
stringlengths
2
2.24k
return_statement
stringlengths
0
2.17k
docstring
stringlengths
0
5.45k
docstring_summary
stringlengths
0
3.83k
func_begin
int64
1
13.4k
func_end
int64
2
13.4k
function
stringlengths
28
56.4k
url
stringlengths
106
209
project
int64
1
48
executed_lines
list
executed_lines_pc
float64
0
153
missing_lines
list
missing_lines_pc
float64
0
100
covered
bool
2 classes
filecoverage
float64
2.53
100
function_lines
int64
2
1.46k
mccabe
int64
1
253
coverage
float64
0
100
docstring_lines
int64
0
112
function_nodoc
stringlengths
9
56.4k
id
int64
0
29.8k
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/debug.py
log_errors.__init__
(self, print_func, label=None, stack=True, repr_len=REPR_LEN)
125
127
def __init__(self, print_func, label=None, stack=True, repr_len=REPR_LEN): LabeledContextDecorator.__init__(self, print_func, label=label, repr_len=repr_len) self.stack = stack
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/debug.py#L125-L127
29
[ 0, 1, 2 ]
100
[]
0
true
82.781457
3
1
100
0
def __init__(self, print_func, label=None, stack=True, repr_len=REPR_LEN): LabeledContextDecorator.__init__(self, print_func, label=label, repr_len=repr_len) self.stack = stack
19,961
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/debug.py
log_errors.__enter__
(self)
return self
129
130
def __enter__(self): return self
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/debug.py#L129-L130
29
[ 0, 1 ]
100
[]
0
true
82.781457
2
1
100
0
def __enter__(self): return self
19,962
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/debug.py
log_errors.__exit__
(self, exc_type, exc_value, tb)
132
138
def __exit__(self, exc_type, exc_value, tb): if exc_type: if self.stack: exc_message = ''.join(traceback.format_exception(exc_type, exc_value, tb)) else: exc_message = '%s: %s' % (exc_type.__name__, exc_value) self.print_func(_format_error(self.label, exc_message, self.stack))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/debug.py#L132-L138
29
[ 0, 1, 2, 3, 5, 6 ]
85.714286
[]
0
false
82.781457
7
3
100
0
def __exit__(self, exc_type, exc_value, tb): if exc_type: if self.stack: exc_message = ''.join(traceback.format_exception(exc_type, exc_value, tb)) else: exc_message = '%s: %s' % (exc_type.__name__, exc_value) self.print_func(_format_error(self.label, exc_message, self.stack))
19,963
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/debug.py
log_durations.__init__
(self, print_func, label=None, unit='auto', threshold=-1, repr_len=REPR_LEN)
166
171
def __init__(self, print_func, label=None, unit='auto', threshold=-1, repr_len=REPR_LEN): LabeledContextDecorator.__init__(self, print_func, label=label, repr_len=repr_len) if unit not in time_formatters: raise ValueError('Unknown time unit: %s. It should be ns, mks, ms, s or auto.' % unit) self.format_time = time_formatters[unit] self.threshold = threshold
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/debug.py#L166-L171
29
[ 0, 1, 2, 4, 5 ]
83.333333
[ 3 ]
16.666667
false
82.781457
6
2
83.333333
0
def __init__(self, print_func, label=None, unit='auto', threshold=-1, repr_len=REPR_LEN): LabeledContextDecorator.__init__(self, print_func, label=label, repr_len=repr_len) if unit not in time_formatters: raise ValueError('Unknown time unit: %s. It should be ns, mks, ms, s or auto.' % unit) self.format_time = time_formatters[unit] self.threshold = threshold
19,964
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/debug.py
log_durations.__enter__
(self)
return self
173
175
def __enter__(self): self.start = timer() return self
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/debug.py#L173-L175
29
[ 0, 1, 2 ]
100
[]
0
true
82.781457
3
1
100
0
def __enter__(self): self.start = timer() return self
19,965
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/debug.py
log_durations.__exit__
(self, *exc)
177
181
def __exit__(self, *exc): duration = timer() - self.start if duration >= self.threshold: duration_str = self.format_time(duration) self.print_func("%s in %s" % (duration_str, self.label) if self.label else duration_str)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/debug.py#L177-L181
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
82.781457
5
2
100
0
def __exit__(self, *exc): duration = timer() - self.start if duration >= self.threshold: duration_str = self.format_time(duration) self.print_func("%s in %s" % (duration_str, self.label) if self.label else duration_str)
19,966
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
repeatedly
(f, n=EMPTY)
return (f() for _ in _repeat)
Takes a function of no args, presumably with side effects, and returns an infinite (or length n) iterator of calls to it.
Takes a function of no args, presumably with side effects, and returns an infinite (or length n) iterator of calls to it.
30
34
def repeatedly(f, n=EMPTY): """Takes a function of no args, presumably with side effects, and returns an infinite (or length n) iterator of calls to it.""" _repeat = repeat(None) if n is EMPTY else repeat(None, n) return (f() for _ in _repeat)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L30-L34
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
1
100
2
def repeatedly(f, n=EMPTY): _repeat = repeat(None) if n is EMPTY else repeat(None, n) return (f() for _ in _repeat)
19,967
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
iterate
(f, x)
Returns an infinite iterator of `x, f(x), f(f(x)), ...`
Returns an infinite iterator of `x, f(x), f(f(x)), ...`
36
40
def iterate(f, x): """Returns an infinite iterator of `x, f(x), f(f(x)), ...`""" while True: yield x x = f(x)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L36-L40
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
2
100
1
def iterate(f, x): while True: yield x x = f(x)
19,968
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
take
(n, seq)
return list(islice(seq, n))
Returns a list of first n items in the sequence, or all items if there are fewer than n.
Returns a list of first n items in the sequence, or all items if there are fewer than n.
43
46
def take(n, seq): """Returns a list of first n items in the sequence, or all items if there are fewer than n.""" return list(islice(seq, n))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L43-L46
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def take(n, seq): return list(islice(seq, n))
19,969
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
drop
(n, seq)
return islice(seq, n, None)
Skips first n items in the sequence, yields the rest.
Skips first n items in the sequence, yields the rest.
48
50
def drop(n, seq): """Skips first n items in the sequence, yields the rest.""" return islice(seq, n, None)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L48-L50
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def drop(n, seq): return islice(seq, n, None)
19,970
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
first
(seq)
return next(iter(seq), None)
Returns the first item in the sequence. Returns None if the sequence is empty.
Returns the first item in the sequence. Returns None if the sequence is empty.
52
55
def first(seq): """Returns the first item in the sequence. Returns None if the sequence is empty.""" return next(iter(seq), None)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L52-L55
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def first(seq): return next(iter(seq), None)
19,971
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
second
(seq)
return first(rest(seq))
Returns second item in the sequence. Returns None if there are less than two items in it.
Returns second item in the sequence. Returns None if there are less than two items in it.
57
60
def second(seq): """Returns second item in the sequence. Returns None if there are less than two items in it.""" return first(rest(seq))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L57-L60
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def second(seq): return first(rest(seq))
19,972
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
nth
(n, seq)
Returns nth item in the sequence or None if no such item exists.
Returns nth item in the sequence or None if no such item exists.
62
69
def nth(n, seq): """Returns nth item in the sequence or None if no such item exists.""" try: return seq[n] except IndexError: return None except TypeError: return next(islice(seq, n, None), None)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L62-L69
29
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
93.014706
8
3
100
1
def nth(n, seq): try: return seq[n] except IndexError: return None except TypeError: return next(islice(seq, n, None), None)
19,973
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
last
(seq)
Returns the last item in the sequence or iterator. Returns None if the sequence is empty.
Returns the last item in the sequence or iterator. Returns None if the sequence is empty.
71
82
def last(seq): """Returns the last item in the sequence or iterator. Returns None if the sequence is empty.""" try: return seq[-1] except IndexError: return None except TypeError: item = None for item in seq: pass return item
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L71-L82
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
93.014706
12
4
100
2
def last(seq): try: return seq[-1] except IndexError: return None except TypeError: item = None for item in seq: pass return item
19,974
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
rest
(seq)
return drop(1, seq)
Skips first item in the sequence, yields the rest.
Skips first item in the sequence, yields the rest.
84
86
def rest(seq): """Skips first item in the sequence, yields the rest.""" return drop(1, seq)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L84-L86
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def rest(seq): return drop(1, seq)
19,975
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
butlast
(seq)
Iterates over all elements of the sequence but last.
Iterates over all elements of the sequence but last.
88
98
def butlast(seq): """Iterates over all elements of the sequence but last.""" it = iter(seq) try: prev = next(it) except StopIteration: pass else: for item in it: yield prev prev = item
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L88-L98
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
93.014706
11
3
100
1
def butlast(seq): it = iter(seq) try: prev = next(it) except StopIteration: pass else: for item in it: yield prev prev = item
19,976
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
ilen
(seq)
return next(counter)
Consumes an iterable not reading it into memory and returns the number of items.
Consumes an iterable not reading it into memory and returns the number of items.
100
106
def ilen(seq): """Consumes an iterable not reading it into memory and returns the number of items.""" # NOTE: implementation borrowed from http://stackoverflow.com/a/15112059/753382 counter = count() deque(zip(seq, counter), maxlen=0) # (consume at C speed) return next(counter)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L100-L106
29
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
93.014706
7
1
100
2
def ilen(seq): # NOTE: implementation borrowed from http://stackoverflow.com/a/15112059/753382 counter = count() deque(zip(seq, counter), maxlen=0) # (consume at C speed) return next(counter)
19,977
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lmap
(f, *seqs)
return _lmap(make_func(f, builtin=PY2), *seqs)
An extended version of builtin map() returning a list. Derives a mapper from string, int, slice, dict or set.
An extended version of builtin map() returning a list. Derives a mapper from string, int, slice, dict or set.
111
114
def lmap(f, *seqs): """An extended version of builtin map() returning a list. Derives a mapper from string, int, slice, dict or set.""" return _lmap(make_func(f, builtin=PY2), *seqs)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L111-L114
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def lmap(f, *seqs): return _lmap(make_func(f, builtin=PY2), *seqs)
19,978
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lfilter
(pred, seq)
return _lfilter(make_pred(pred, builtin=PY2), seq)
An extended version of builtin filter() returning a list. Derives a predicate from string, int, slice, dict or set.
An extended version of builtin filter() returning a list. Derives a predicate from string, int, slice, dict or set.
116
119
def lfilter(pred, seq): """An extended version of builtin filter() returning a list. Derives a predicate from string, int, slice, dict or set.""" return _lfilter(make_pred(pred, builtin=PY2), seq)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L116-L119
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def lfilter(pred, seq): return _lfilter(make_pred(pred, builtin=PY2), seq)
19,979
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
map
(f, *seqs)
return _map(make_func(f, builtin=PY2), *seqs)
An extended version of builtin map(). Derives a mapper from string, int, slice, dict or set.
An extended version of builtin map(). Derives a mapper from string, int, slice, dict or set.
121
124
def map(f, *seqs): """An extended version of builtin map(). Derives a mapper from string, int, slice, dict or set.""" return _map(make_func(f, builtin=PY2), *seqs)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L121-L124
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def map(f, *seqs): return _map(make_func(f, builtin=PY2), *seqs)
19,980
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
filter
(pred, seq)
return _filter(make_pred(pred, builtin=PY2), seq)
An extended version of builtin filter(). Derives a predicate from string, int, slice, dict or set.
An extended version of builtin filter(). Derives a predicate from string, int, slice, dict or set.
126
129
def filter(pred, seq): """An extended version of builtin filter(). Derives a predicate from string, int, slice, dict or set.""" return _filter(make_pred(pred, builtin=PY2), seq)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L126-L129
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def filter(pred, seq): return _filter(make_pred(pred, builtin=PY2), seq)
19,981
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lremove
(pred, seq)
return list(remove(pred, seq))
Creates a list if items passing given predicate.
Creates a list if items passing given predicate.
141
143
def lremove(pred, seq): """Creates a list if items passing given predicate.""" return list(remove(pred, seq))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L141-L143
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def lremove(pred, seq): return list(remove(pred, seq))
19,982
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
remove
(pred, seq)
return filterfalse(make_pred(pred, builtin=PY2), seq)
Iterates items passing given predicate.
Iterates items passing given predicate.
145
147
def remove(pred, seq): """Iterates items passing given predicate.""" return filterfalse(make_pred(pred, builtin=PY2), seq)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L145-L147
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def remove(pred, seq): return filterfalse(make_pred(pred, builtin=PY2), seq)
19,983
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lkeep
(f, seq=EMPTY)
return list(keep(f, seq))
Maps seq with f and keeps only truthy results. Simply lists truthy values in one argument version.
Maps seq with f and keeps only truthy results. Simply lists truthy values in one argument version.
149
152
def lkeep(f, seq=EMPTY): """Maps seq with f and keeps only truthy results. Simply lists truthy values in one argument version.""" return list(keep(f, seq))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L149-L152
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def lkeep(f, seq=EMPTY): return list(keep(f, seq))
19,984
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
keep
(f, seq=EMPTY)
Maps seq with f and iterates truthy results. Simply iterates truthy values in one argument version.
Maps seq with f and iterates truthy results. Simply iterates truthy values in one argument version.
154
160
def keep(f, seq=EMPTY): """Maps seq with f and iterates truthy results. Simply iterates truthy values in one argument version.""" if seq is EMPTY: return _filter(bool, f) else: return _filter(bool, xmap(f, seq))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L154-L160
29
[ 0, 1, 2, 3, 4, 6 ]
85.714286
[]
0
false
93.014706
7
2
100
2
def keep(f, seq=EMPTY): if seq is EMPTY: return _filter(bool, f) else: return _filter(bool, xmap(f, seq))
19,985
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
without
(seq, *items)
Iterates over sequence skipping items.
Iterates over sequence skipping items.
162
166
def without(seq, *items): """Iterates over sequence skipping items.""" for value in seq: if value not in items: yield value
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L162-L166
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
3
100
1
def without(seq, *items): for value in seq: if value not in items: yield value
19,986
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lwithout
(seq, *items)
return list(without(seq, *items))
Removes items from sequence, preserves order.
Removes items from sequence, preserves order.
168
170
def lwithout(seq, *items): """Removes items from sequence, preserves order.""" return list(without(seq, *items))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L168-L170
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def lwithout(seq, *items): return list(without(seq, *items))
19,987
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lconcat
(*seqs)
return list(chain(*seqs))
Concatenates several sequences.
Concatenates several sequences.
173
175
def lconcat(*seqs): """Concatenates several sequences.""" return list(chain(*seqs))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L173-L175
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def lconcat(*seqs): return list(chain(*seqs))
19,988
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lcat
(seqs)
return list(cat(seqs))
Concatenates the sequence of sequences.
Concatenates the sequence of sequences.
178
180
def lcat(seqs): """Concatenates the sequence of sequences.""" return list(cat(seqs))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L178-L180
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def lcat(seqs): return list(cat(seqs))
19,989
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
flatten
(seq, follow=is_seqcont)
Flattens arbitrary nested sequence. Unpacks an item if follow(item) is truthy.
Flattens arbitrary nested sequence. Unpacks an item if follow(item) is truthy.
183
192
def flatten(seq, follow=is_seqcont): """Flattens arbitrary nested sequence. Unpacks an item if follow(item) is truthy.""" for item in seq: if follow(item): # TODO: use `yield from` when Python 2 is dropped ;) for sub in flatten(item, follow): yield sub else: yield item
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L183-L192
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 9 ]
90
[]
0
false
93.014706
10
4
100
2
def flatten(seq, follow=is_seqcont): for item in seq: if follow(item): # TODO: use `yield from` when Python 2 is dropped ;) for sub in flatten(item, follow): yield sub else: yield item
19,990
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lflatten
(seq, follow=is_seqcont)
return list(flatten(seq, follow))
Iterates over arbitrary nested sequence. Dives into when follow(item) is truthy.
Iterates over arbitrary nested sequence. Dives into when follow(item) is truthy.
194
197
def lflatten(seq, follow=is_seqcont): """Iterates over arbitrary nested sequence. Dives into when follow(item) is truthy.""" return list(flatten(seq, follow))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L194-L197
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def lflatten(seq, follow=is_seqcont): return list(flatten(seq, follow))
19,991
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lmapcat
(f, *seqs)
return lcat(xmap(f, *seqs))
Maps given sequence(s) and concatenates the results.
Maps given sequence(s) and concatenates the results.
199
201
def lmapcat(f, *seqs): """Maps given sequence(s) and concatenates the results.""" return lcat(xmap(f, *seqs))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L199-L201
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def lmapcat(f, *seqs): return lcat(xmap(f, *seqs))
19,992
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
mapcat
(f, *seqs)
return cat(xmap(f, *seqs))
Maps given sequence(s) and chains the results.
Maps given sequence(s) and chains the results.
203
205
def mapcat(f, *seqs): """Maps given sequence(s) and chains the results.""" return cat(xmap(f, *seqs))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L203-L205
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def mapcat(f, *seqs): return cat(xmap(f, *seqs))
19,993
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
interleave
(*seqs)
return cat(zip(*seqs))
Yields first item of each sequence, then second one and so on.
Yields first item of each sequence, then second one and so on.
207
209
def interleave(*seqs): """Yields first item of each sequence, then second one and so on.""" return cat(zip(*seqs))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L207-L209
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def interleave(*seqs): return cat(zip(*seqs))
19,994
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
interpose
(sep, seq)
return drop(1, interleave(repeat(sep), seq))
Yields items of the sequence alternating with sep.
Yields items of the sequence alternating with sep.
211
213
def interpose(sep, seq): """Yields items of the sequence alternating with sep.""" return drop(1, interleave(repeat(sep), seq))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L211-L213
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def interpose(sep, seq): return drop(1, interleave(repeat(sep), seq))
19,995
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
takewhile
(pred, seq=EMPTY)
return _takewhile(pred, seq)
Yields sequence items until first predicate fail. Stops on first falsy value in one argument version.
Yields sequence items until first predicate fail. Stops on first falsy value in one argument version.
215
222
def takewhile(pred, seq=EMPTY): """Yields sequence items until first predicate fail. Stops on first falsy value in one argument version.""" if seq is EMPTY: pred, seq = bool, pred else: pred = make_pred(pred) return _takewhile(pred, seq)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L215-L222
29
[ 0, 1, 2, 3, 4, 6, 7 ]
87.5
[]
0
false
93.014706
8
2
100
2
def takewhile(pred, seq=EMPTY): if seq is EMPTY: pred, seq = bool, pred else: pred = make_pred(pred) return _takewhile(pred, seq)
19,996
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
dropwhile
(pred, seq=EMPTY)
return _dropwhile(pred, seq)
Skips the start of the sequence passing pred (or just truthy), then iterates over the rest.
Skips the start of the sequence passing pred (or just truthy), then iterates over the rest.
224
231
def dropwhile(pred, seq=EMPTY): """Skips the start of the sequence passing pred (or just truthy), then iterates over the rest.""" if seq is EMPTY: pred, seq = bool, pred else: pred = make_pred(pred) return _dropwhile(pred, seq)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L224-L231
29
[ 0, 1, 2, 3, 6, 7 ]
75
[ 4 ]
12.5
false
93.014706
8
2
87.5
2
def dropwhile(pred, seq=EMPTY): if seq is EMPTY: pred, seq = bool, pred else: pred = make_pred(pred) return _dropwhile(pred, seq)
19,997
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
ldistinct
(seq, key=EMPTY)
return list(distinct(seq, key))
Removes duplicates from sequences, preserves order.
Removes duplicates from sequences, preserves order.
234
236
def ldistinct(seq, key=EMPTY): """Removes duplicates from sequences, preserves order.""" return list(distinct(seq, key))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L234-L236
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def ldistinct(seq, key=EMPTY): return list(distinct(seq, key))
19,998
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
distinct
(seq, key=EMPTY)
Iterates over sequence skipping duplicates
Iterates over sequence skipping duplicates
238
253
def distinct(seq, key=EMPTY): """Iterates over sequence skipping duplicates""" seen = set() # check if key is supplied out of loop for efficiency if key is EMPTY: for item in seq: if item not in seen: seen.add(item) yield item else: key = make_func(key) for item in seq: k = key(item) if k not in seen: seen.add(k) yield item
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L238-L253
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
93.014706
16
6
100
1
def distinct(seq, key=EMPTY): seen = set() # check if key is supplied out of loop for efficiency if key is EMPTY: for item in seq: if item not in seen: seen.add(item) yield item else: key = make_func(key) for item in seq: k = key(item) if k not in seen: seen.add(k) yield item
19,999
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
split
(pred, seq)
return _split(yes), _split(no)
Lazily splits items which pass the predicate from the ones that don't. Returns a pair (passed, failed) of respective iterators.
Lazily splits items which pass the predicate from the ones that don't. Returns a pair (passed, failed) of respective iterators.
256
272
def split(pred, seq): """Lazily splits items which pass the predicate from the ones that don't. Returns a pair (passed, failed) of respective iterators.""" pred = make_pred(pred) yes, no = deque(), deque() splitter = (yes.append(item) if pred(item) else no.append(item) for item in seq) def _split(q): while True: while q: yield q.popleft() try: next(splitter) except StopIteration: return return _split(yes), _split(no)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L256-L272
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
93.014706
17
5
100
2
def split(pred, seq): pred = make_pred(pred) yes, no = deque(), deque() splitter = (yes.append(item) if pred(item) else no.append(item) for item in seq) def _split(q): while True: while q: yield q.popleft() try: next(splitter) except StopIteration: return return _split(yes), _split(no)
20,000
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lsplit
(pred, seq)
return yes, no
Splits items which pass the predicate from the ones that don't. Returns a pair (passed, failed) of respective lists.
Splits items which pass the predicate from the ones that don't. Returns a pair (passed, failed) of respective lists.
274
284
def lsplit(pred, seq): """Splits items which pass the predicate from the ones that don't. Returns a pair (passed, failed) of respective lists.""" pred = make_pred(pred) yes, no = [], [] for item in seq: if pred(item): yes.append(item) else: no.append(item) return yes, no
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L274-L284
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 9, 10 ]
90.909091
[]
0
false
93.014706
11
3
100
2
def lsplit(pred, seq): pred = make_pred(pred) yes, no = [], [] for item in seq: if pred(item): yes.append(item) else: no.append(item) return yes, no
20,001
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
split_at
(n, seq)
return islice(a, n), islice(b, n, None)
Lazily splits the sequence at given position, returning a pair of iterators over its start and tail.
Lazily splits the sequence at given position, returning a pair of iterators over its start and tail.
287
291
def split_at(n, seq): """Lazily splits the sequence at given position, returning a pair of iterators over its start and tail.""" a, b = tee(seq) return islice(a, n), islice(b, n, None)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L287-L291
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
1
100
2
def split_at(n, seq): a, b = tee(seq) return islice(a, n), islice(b, n, None)
20,002
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lsplit_at
(n, seq)
return list(a), list(b)
Splits the sequence at given position, returning a tuple of its start and tail.
Splits the sequence at given position, returning a tuple of its start and tail.
293
297
def lsplit_at(n, seq): """Splits the sequence at given position, returning a tuple of its start and tail.""" a, b = split_at(n, seq) return list(a), list(b)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L293-L297
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
1
100
2
def lsplit_at(n, seq): a, b = split_at(n, seq) return list(a), list(b)
20,003
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
split_by
(pred, seq)
return takewhile(pred, a), dropwhile(pred, b)
Lazily splits the start of the sequence, consisting of items passing pred, from the rest of it.
Lazily splits the start of the sequence, consisting of items passing pred, from the rest of it.
299
303
def split_by(pred, seq): """Lazily splits the start of the sequence, consisting of items passing pred, from the rest of it.""" a, b = tee(seq) return takewhile(pred, a), dropwhile(pred, b)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L299-L303
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
1
100
2
def split_by(pred, seq): a, b = tee(seq) return takewhile(pred, a), dropwhile(pred, b)
20,004
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lsplit_by
(pred, seq)
return list(a), list(b)
Splits the start of the sequence, consisting of items passing pred, from the rest of it.
Splits the start of the sequence, consisting of items passing pred, from the rest of it.
305
309
def lsplit_by(pred, seq): """Splits the start of the sequence, consisting of items passing pred, from the rest of it.""" a, b = split_by(pred, seq) return list(a), list(b)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L305-L309
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
1
100
2
def lsplit_by(pred, seq): a, b = split_by(pred, seq) return list(a), list(b)
20,005
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
group_by
(f, seq)
return result
Groups given sequence items into a mapping f(item) -> [item, ...].
Groups given sequence items into a mapping f(item) -> [item, ...].
312
318
def group_by(f, seq): """Groups given sequence items into a mapping f(item) -> [item, ...].""" f = make_func(f) result = defaultdict(list) for item in seq: result[f(item)].append(item) return result
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L312-L318
29
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
93.014706
7
2
100
1
def group_by(f, seq): f = make_func(f) result = defaultdict(list) for item in seq: result[f(item)].append(item) return result
20,006
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
group_by_keys
(get_keys, seq)
return result
Groups items having multiple keys into a mapping key -> [item, ...]. Item might be repeated under several keys.
Groups items having multiple keys into a mapping key -> [item, ...]. Item might be repeated under several keys.
321
329
def group_by_keys(get_keys, seq): """Groups items having multiple keys into a mapping key -> [item, ...]. Item might be repeated under several keys.""" get_keys = make_func(get_keys) result = defaultdict(list) for item in seq: for k in get_keys(item): result[k].append(item) return result
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L321-L329
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
93.014706
9
3
100
2
def group_by_keys(get_keys, seq): get_keys = make_func(get_keys) result = defaultdict(list) for item in seq: for k in get_keys(item): result[k].append(item) return result
20,007
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
group_values
(seq)
return result
Takes a sequence of (key, value) pairs and groups values by keys.
Takes a sequence of (key, value) pairs and groups values by keys.
332
337
def group_values(seq): """Takes a sequence of (key, value) pairs and groups values by keys.""" result = defaultdict(list) for key, value in seq: result[key].append(value) return result
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L332-L337
29
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
93.014706
6
2
100
1
def group_values(seq): result = defaultdict(list) for key, value in seq: result[key].append(value) return result
20,008
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
count_by
(f, seq)
return result
Counts numbers of occurrences of values of f() on elements of given sequence.
Counts numbers of occurrences of values of f() on elements of given sequence.
340
347
def count_by(f, seq): """Counts numbers of occurrences of values of f() on elements of given sequence.""" f = make_func(f) result = defaultdict(int) for item in seq: result[f(item)] += 1 return result
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L340-L347
29
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
93.014706
8
2
100
2
def count_by(f, seq): f = make_func(f) result = defaultdict(int) for item in seq: result[f(item)] += 1 return result
20,009
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
count_reps
(seq)
return result
Counts number occurrences of each value in the sequence.
Counts number occurrences of each value in the sequence.
350
355
def count_reps(seq): """Counts number occurrences of each value in the sequence.""" result = defaultdict(int) for item in seq: result[item] += 1 return result
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L350-L355
29
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
93.014706
6
2
100
1
def count_reps(seq): result = defaultdict(int) for item in seq: result[item] += 1 return result
20,010
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
_cut_seq
(drop_tail, n, step, seq)
return (seq[i:i+n] for i in range(0, limit, step))
359
361
def _cut_seq(drop_tail, n, step, seq): limit = len(seq)-n+1 if drop_tail else len(seq) return (seq[i:i+n] for i in range(0, limit, step))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L359-L361
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
0
def _cut_seq(drop_tail, n, step, seq): limit = len(seq)-n+1 if drop_tail else len(seq) return (seq[i:i+n] for i in range(0, limit, step))
20,011
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
_cut_iter
(drop_tail, n, step, seq)
363
374
def _cut_iter(drop_tail, n, step, seq): it = iter(seq) pool = take(n, it) while True: if len(pool) < n: break yield pool pool = pool[step:] pool.extend(islice(it, step)) if not drop_tail: for item in _cut_seq(drop_tail, n, step, pool): yield item
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L363-L374
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
93.014706
12
5
100
0
def _cut_iter(drop_tail, n, step, seq): it = iter(seq) pool = take(n, it) while True: if len(pool) < n: break yield pool pool = pool[step:] pool.extend(islice(it, step)) if not drop_tail: for item in _cut_seq(drop_tail, n, step, pool): yield item
20,012
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
_cut
(drop_tail, n, step, seq=EMPTY)
376
383
def _cut(drop_tail, n, step, seq=EMPTY): if seq is EMPTY: step, seq = n, step # NOTE: range() is capable of slicing in python 3, if isinstance(seq, Sequence) and (PY3 or not isinstance(seq, range)): return _cut_seq(drop_tail, n, step, seq) else: return _cut_iter(drop_tail, n, step, seq)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L376-L383
29
[ 0, 1, 2, 3, 4, 5, 7 ]
87.5
[]
0
false
93.014706
8
5
100
0
def _cut(drop_tail, n, step, seq=EMPTY): if seq is EMPTY: step, seq = n, step # NOTE: range() is capable of slicing in python 3, if isinstance(seq, Sequence) and (PY3 or not isinstance(seq, range)): return _cut_seq(drop_tail, n, step, seq) else: return _cut_iter(drop_tail, n, step, seq)
20,013
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
partition
(n, step, seq=EMPTY)
return _cut(True, n, step, seq)
Lazily partitions seq into parts of length n. Skips step items between parts if passed. Non-fitting tail is ignored.
Lazily partitions seq into parts of length n. Skips step items between parts if passed. Non-fitting tail is ignored.
385
388
def partition(n, step, seq=EMPTY): """Lazily partitions seq into parts of length n. Skips step items between parts if passed. Non-fitting tail is ignored.""" return _cut(True, n, step, seq)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L385-L388
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def partition(n, step, seq=EMPTY): return _cut(True, n, step, seq)
20,014
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lpartition
(n, step, seq=EMPTY)
return list(partition(n, step, seq))
Partitions seq into parts of length n. Skips step items between parts if passed. Non-fitting tail is ignored.
Partitions seq into parts of length n. Skips step items between parts if passed. Non-fitting tail is ignored.
390
393
def lpartition(n, step, seq=EMPTY): """Partitions seq into parts of length n. Skips step items between parts if passed. Non-fitting tail is ignored.""" return list(partition(n, step, seq))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L390-L393
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def lpartition(n, step, seq=EMPTY): return list(partition(n, step, seq))
20,015
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
chunks
(n, step, seq=EMPTY)
return _cut(False, n, step, seq)
Lazily chunks seq into parts of length n or less. Skips step items between parts if passed.
Lazily chunks seq into parts of length n or less. Skips step items between parts if passed.
395
398
def chunks(n, step, seq=EMPTY): """Lazily chunks seq into parts of length n or less. Skips step items between parts if passed.""" return _cut(False, n, step, seq)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L395-L398
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def chunks(n, step, seq=EMPTY): return _cut(False, n, step, seq)
20,016
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lchunks
(n, step, seq=EMPTY)
return list(chunks(n, step, seq))
Chunks seq into parts of length n or less. Skips step items between parts if passed.
Chunks seq into parts of length n or less. Skips step items between parts if passed.
400
403
def lchunks(n, step, seq=EMPTY): """Chunks seq into parts of length n or less. Skips step items between parts if passed.""" return list(chunks(n, step, seq))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L400-L403
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
2
def lchunks(n, step, seq=EMPTY): return list(chunks(n, step, seq))
20,017
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
partition_by
(f, seq)
Lazily partition seq into continuous chunks with constant value of f.
Lazily partition seq into continuous chunks with constant value of f.
405
409
def partition_by(f, seq): """Lazily partition seq into continuous chunks with constant value of f.""" f = make_func(f) for _, items in groupby(seq, f): yield items
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L405-L409
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
2
100
1
def partition_by(f, seq): f = make_func(f) for _, items in groupby(seq, f): yield items
20,018
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lpartition_by
(f, seq)
return _lmap(list, partition_by(f, seq))
Partition seq into continuous chunks with constant value of f.
Partition seq into continuous chunks with constant value of f.
411
413
def lpartition_by(f, seq): """Partition seq into continuous chunks with constant value of f.""" return _lmap(list, partition_by(f, seq))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L411-L413
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def lpartition_by(f, seq): return _lmap(list, partition_by(f, seq))
20,019
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
with_prev
(seq, fill=None)
return zip(a, chain([fill], b))
Yields each item paired with its preceding: (item, prev).
Yields each item paired with its preceding: (item, prev).
416
419
def with_prev(seq, fill=None): """Yields each item paired with its preceding: (item, prev).""" a, b = tee(seq) return zip(a, chain([fill], b))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L416-L419
29
[ 0, 1, 2, 3 ]
100
[]
0
true
93.014706
4
1
100
1
def with_prev(seq, fill=None): a, b = tee(seq) return zip(a, chain([fill], b))
20,020
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
with_next
(seq, fill=None)
return zip(a, chain(b, [fill]))
Yields each item paired with its following: (item, next).
Yields each item paired with its following: (item, next).
421
425
def with_next(seq, fill=None): """Yields each item paired with its following: (item, next).""" a, b = tee(seq) next(b, None) return zip(a, chain(b, [fill]))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L421-L425
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
1
100
1
def with_next(seq, fill=None): a, b = tee(seq) next(b, None) return zip(a, chain(b, [fill]))
20,021
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
pairwise
(seq)
return zip(a, b)
Yields all pairs of neighboring items in seq.
Yields all pairs of neighboring items in seq.
429
433
def pairwise(seq): """Yields all pairs of neighboring items in seq.""" a, b = tee(seq) next(b, None) return zip(a, b)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L429-L433
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
93.014706
5
1
100
1
def pairwise(seq): a, b = tee(seq) next(b, None) return zip(a, b)
20,022
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lreductions
(f, seq, acc=EMPTY)
return list(reductions(f, seq, acc))
Lists intermediate reductions of seq by f.
Lists intermediate reductions of seq by f.
472
474
def lreductions(f, seq, acc=EMPTY): """Lists intermediate reductions of seq by f.""" return list(reductions(f, seq, acc))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L472-L474
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def lreductions(f, seq, acc=EMPTY): return list(reductions(f, seq, acc))
20,023
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
sums
(seq, acc=EMPTY)
return reductions(operator.add, seq, acc)
Yields partial sums of seq.
Yields partial sums of seq.
476
478
def sums(seq, acc=EMPTY): """Yields partial sums of seq.""" return reductions(operator.add, seq, acc)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L476-L478
29
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
93.014706
3
1
66.666667
1
def sums(seq, acc=EMPTY): return reductions(operator.add, seq, acc)
20,024
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/seqs.py
lsums
(seq, acc=EMPTY)
return lreductions(operator.add, seq, acc)
Lists partial sums of seq.
Lists partial sums of seq.
480
482
def lsums(seq, acc=EMPTY): """Lists partial sums of seq.""" return lreductions(operator.add, seq, acc)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/seqs.py#L480-L482
29
[ 0, 1, 2 ]
100
[]
0
true
93.014706
3
1
100
1
def lsums(seq, acc=EMPTY): return lreductions(operator.add, seq, acc)
20,025
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/tree.py
tree_leaves
(root, follow=is_seqcont, children=iter)
Iterates over tree leaves.
Iterates over tree leaves.
8
19
def tree_leaves(root, follow=is_seqcont, children=iter): """Iterates over tree leaves.""" q = deque([[root]]) while q: node_iter = iter(q.pop()) for sub in node_iter: if follow(sub): q.append(node_iter) q.append(children(sub)) break else: yield sub
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/tree.py#L8-L19
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
100
12
4
100
1
def tree_leaves(root, follow=is_seqcont, children=iter): q = deque([[root]]) while q: node_iter = iter(q.pop()) for sub in node_iter: if follow(sub): q.append(node_iter) q.append(children(sub)) break else: yield sub
20,026
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/tree.py
ltree_leaves
(root, follow=is_seqcont, children=iter)
return list(tree_leaves(root, follow, children))
Lists tree leaves.
Lists tree leaves.
21
23
def ltree_leaves(root, follow=is_seqcont, children=iter): """Lists tree leaves.""" return list(tree_leaves(root, follow, children))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/tree.py#L21-L23
29
[ 0, 1, 2 ]
100
[]
0
true
100
3
1
100
1
def ltree_leaves(root, follow=is_seqcont, children=iter): return list(tree_leaves(root, follow, children))
20,027
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/tree.py
tree_nodes
(root, follow=is_seqcont, children=iter)
Iterates over all tree nodes.
Iterates over all tree nodes.
26
36
def tree_nodes(root, follow=is_seqcont, children=iter): """Iterates over all tree nodes.""" q = deque([[root]]) while q: node_iter = iter(q.pop()) for sub in node_iter: yield sub if follow(sub): q.append(node_iter) q.append(children(sub)) break
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/tree.py#L26-L36
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
100
11
4
100
1
def tree_nodes(root, follow=is_seqcont, children=iter): q = deque([[root]]) while q: node_iter = iter(q.pop()) for sub in node_iter: yield sub if follow(sub): q.append(node_iter) q.append(children(sub)) break
20,028
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/tree.py
ltree_nodes
(root, follow=is_seqcont, children=iter)
return list(tree_nodes(root, follow, children))
Lists all tree nodes.
Lists all tree nodes.
38
40
def ltree_nodes(root, follow=is_seqcont, children=iter): """Lists all tree nodes.""" return list(tree_nodes(root, follow, children))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/tree.py#L38-L40
29
[ 0, 1, 2 ]
100
[]
0
true
100
3
1
100
1
def ltree_nodes(root, follow=is_seqcont, children=iter): return list(tree_nodes(root, follow, children))
20,029
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/_inspect.py
get_spec
(func, _cache={})
105
159
def get_spec(func, _cache={}): func = getattr(func, '__original__', None) or unwrap(func) try: return _cache[func] except (KeyError, TypeError): pass mod = getattr(func, '__module__', None) if mod in STD_MODULES or mod in ARGS and func.__name__ in ARGS[mod]: _spec = ARGS[mod].get(func.__name__, '*') required, _, optional = _spec.partition('-') req_names = re.findall(r'\w+|\*', required) # a list with dups of * max_n = len(req_names) + len(optional) req_n = len(req_names) spec = Spec(max_n=max_n, names=set(), req_n=req_n, req_names=set(req_names), kw=False) _cache[func] = spec return spec elif isinstance(func, type_classes): # Old style classes without base if not hasattr(func, '__init__'): return Spec(max_n=0, names=set(), req_n=0, req_names=set(), kw=False) # __init__ inherited from builtin classes objclass = getattr(func.__init__, '__objclass__', None) if objclass and objclass is not func: return get_spec(objclass) # Introspect constructor and remove self spec = get_spec(func.__init__) self_set = set([func.__init__.__code__.co_varnames[0]]) return spec._replace(max_n=spec.max_n - 1, names=spec.names - self_set, req_n=spec.req_n - 1, req_names=spec.req_names - self_set) else: try: defaults_n = len(func.__defaults__) except (AttributeError, TypeError): defaults_n = 0 try: varnames = func.__code__.co_varnames n = func.__code__.co_argcount names = set(varnames[:n]) req_n = n - defaults_n req_names = set(varnames[:req_n]) kw = bool(func.__code__.co_flags & CO_VARKEYWORDS) # If there are varargs they could be required, but all keywords args can't be max_n = req_n + 1 if func.__code__.co_flags & CO_VARARGS else n return Spec(max_n=max_n, names=names, req_n=req_n, req_names=req_names, kw=kw) except AttributeError: # We use signature last to be fully backwards compatible. Also it's slower try: sig = signature(func) except (ValueError, TypeError): raise ValueError('Unable to introspect %s() arguments' % (getattr(func, '__qualname__', None) or getattr(func, '__name__', func))) else: spec = _cache[func] = _sig_to_spec(sig) return spec
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/_inspect.py#L105-L159
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44 ]
76.363636
[ 20, 45, 47, 48, 49, 50, 53, 54 ]
14.545455
false
75
55
14
85.454545
0
def get_spec(func, _cache={}): func = getattr(func, '__original__', None) or unwrap(func) try: return _cache[func] except (KeyError, TypeError): pass mod = getattr(func, '__module__', None) if mod in STD_MODULES or mod in ARGS and func.__name__ in ARGS[mod]: _spec = ARGS[mod].get(func.__name__, '*') required, _, optional = _spec.partition('-') req_names = re.findall(r'\w+|\*', required) # a list with dups of * max_n = len(req_names) + len(optional) req_n = len(req_names) spec = Spec(max_n=max_n, names=set(), req_n=req_n, req_names=set(req_names), kw=False) _cache[func] = spec return spec elif isinstance(func, type_classes): # Old style classes without base if not hasattr(func, '__init__'): return Spec(max_n=0, names=set(), req_n=0, req_names=set(), kw=False) # __init__ inherited from builtin classes objclass = getattr(func.__init__, '__objclass__', None) if objclass and objclass is not func: return get_spec(objclass) # Introspect constructor and remove self spec = get_spec(func.__init__) self_set = set([func.__init__.__code__.co_varnames[0]]) return spec._replace(max_n=spec.max_n - 1, names=spec.names - self_set, req_n=spec.req_n - 1, req_names=spec.req_names - self_set) else: try: defaults_n = len(func.__defaults__) except (AttributeError, TypeError): defaults_n = 0 try: varnames = func.__code__.co_varnames n = func.__code__.co_argcount names = set(varnames[:n]) req_n = n - defaults_n req_names = set(varnames[:req_n]) kw = bool(func.__code__.co_flags & CO_VARKEYWORDS) # If there are varargs they could be required, but all keywords args can't be max_n = req_n + 1 if func.__code__.co_flags & CO_VARARGS else n return Spec(max_n=max_n, names=names, req_n=req_n, req_names=req_names, kw=kw) except AttributeError: # We use signature last to be fully backwards compatible. Also it's slower try: sig = signature(func) except (ValueError, TypeError): raise ValueError('Unable to introspect %s() arguments' % (getattr(func, '__qualname__', None) or getattr(func, '__name__', func))) else: spec = _cache[func] = _sig_to_spec(sig) return spec
20,030
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/_inspect.py
_sig_to_spec
(sig)
return Spec(max_n=max_n, names=names, req_n=req_n, req_names=req_names, kw=kw)
162
175
def _sig_to_spec(sig): max_n, names, req_n, req_names, kw = 0, set(), 0, set(), False for name, param in sig.parameters.items(): max_n += 1 if param.kind == param.VAR_KEYWORD: kw = True elif param.kind == param.VAR_POSITIONAL: req_n += 1 else: names.add(name) if param.default is param.empty: req_n += 1 req_names.add(name) return Spec(max_n=max_n, names=names, req_n=req_n, req_names=req_names, kw=kw)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/_inspect.py#L162-L175
29
[ 0 ]
7.142857
[ 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13 ]
85.714286
false
75
14
5
14.285714
0
def _sig_to_spec(sig): max_n, names, req_n, req_names, kw = 0, set(), 0, set(), False for name, param in sig.parameters.items(): max_n += 1 if param.kind == param.VAR_KEYWORD: kw = True elif param.kind == param.VAR_POSITIONAL: req_n += 1 else: names.add(name) if param.default is param.empty: req_n += 1 req_names.add(name) return Spec(max_n=max_n, names=names, req_n=req_n, req_names=req_names, kw=kw)
20,031
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/primitives.py
isnone
(x)
return x is None
11
12
def isnone(x): return x is None
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/primitives.py#L11-L12
29
[ 0 ]
50
[ 1 ]
50
false
58.823529
2
1
50
0
def isnone(x): return x is None
20,032
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/primitives.py
notnone
(x)
return x is not None
14
15
def notnone(x): return x is not None
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/primitives.py#L14-L15
29
[ 0 ]
50
[ 1 ]
50
false
58.823529
2
1
50
0
def notnone(x): return x is not None
20,033
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/primitives.py
inc
(x)
return x + 1
18
19
def inc(x): return x + 1
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/primitives.py#L18-L19
29
[ 0 ]
50
[ 1 ]
50
false
58.823529
2
1
50
0
def inc(x): return x + 1
20,034
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/primitives.py
dec
(x)
return x - 1
21
22
def dec(x): return x - 1
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/primitives.py#L21-L22
29
[ 0 ]
50
[ 1 ]
50
false
58.823529
2
1
50
0
def dec(x): return x - 1
20,035
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/primitives.py
even
(x)
return x % 2 == 0
24
25
def even(x): return x % 2 == 0
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/primitives.py#L24-L25
29
[ 0 ]
50
[ 1 ]
50
false
58.823529
2
1
50
0
def even(x): return x % 2 == 0
20,036
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/primitives.py
odd
(x)
return x % 2 == 1
27
28
def odd(x): return x % 2 == 1
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/primitives.py#L27-L28
29
[ 0 ]
50
[ 1 ]
50
false
58.823529
2
1
50
0
def odd(x): return x % 2 == 1
20,037
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/primitives.py
EmptyType.__repr__
(self)
return 'EMPTY'
5
6
def __repr__(self): return 'EMPTY'
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/primitives.py#L5-L6
29
[ 0 ]
50
[ 1 ]
50
false
58.823529
2
1
50
0
def __repr__(self): return 'EMPTY'
20,038
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
decorator
(deco)
return wraps(deco)(decorator_fab)
Transforms a flat wrapper into decorator:: @decorator def func(call, methods, content_type=DEFAULT): # These are decorator params # Access call arg by name if call.request.method not in methods: # ... # Decorated functions and all the arguments are accesible as: print(call._func, call_args, call._kwargs) # Finally make a call: return call()
Transforms a flat wrapper into decorator::
10
37
def decorator(deco): """ Transforms a flat wrapper into decorator:: @decorator def func(call, methods, content_type=DEFAULT): # These are decorator params # Access call arg by name if call.request.method not in methods: # ... # Decorated functions and all the arguments are accesible as: print(call._func, call_args, call._kwargs) # Finally make a call: return call() """ if has_single_arg(deco): return make_decorator(deco) elif has_1pos_and_kwonly(deco): # Any arguments after first become decorator arguments # And a decorator with arguments is essentially a decorator fab def decorator_fab(_func=None, **dkwargs): # TODO: make _func pos only in Python 3 if _func is not None: return make_decorator(deco, (), dkwargs)(_func) return make_decorator(deco, (), dkwargs) else: def decorator_fab(*dargs, **dkwargs): return make_decorator(deco, dargs, dkwargs) return wraps(deco)(decorator_fab)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L10-L37
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ]
100
[]
0
true
58.181818
28
6
100
11
def decorator(deco): if has_single_arg(deco): return make_decorator(deco) elif has_1pos_and_kwonly(deco): # Any arguments after first become decorator arguments # And a decorator with arguments is essentially a decorator fab def decorator_fab(_func=None, **dkwargs): # TODO: make _func pos only in Python 3 if _func is not None: return make_decorator(deco, (), dkwargs)(_func) return make_decorator(deco, (), dkwargs) else: def decorator_fab(*dargs, **dkwargs): return make_decorator(deco, dargs, dkwargs) return wraps(deco)(decorator_fab)
20,039
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
make_decorator
(deco, dargs=(), dkwargs={})
return _decorator
40
51
def make_decorator(deco, dargs=(), dkwargs={}): @wraps(deco) def _decorator(func): def wrapper(*args, **kwargs): call = Call(func, args, kwargs) return deco(call, *dargs, **dkwargs) return wraps(func)(wrapper) # NOTE: should I update name to show args? # Save these for introspection _decorator._func, _decorator._args, _decorator._kwargs = deco, dargs, dkwargs return _decorator
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L40-L51
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
100
[]
0
true
58.181818
12
3
100
0
def make_decorator(deco, dargs=(), dkwargs={}): @wraps(deco) def _decorator(func): def wrapper(*args, **kwargs): call = Call(func, args, kwargs) return deco(call, *dargs, **dkwargs) return wraps(func)(wrapper) # NOTE: should I update name to show args? # Save these for introspection _decorator._func, _decorator._args, _decorator._kwargs = deco, dargs, dkwargs return _decorator
20,040
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
get_argnames
(func)
return func.__code__.co_varnames[:func.__code__.co_argcount]
112
114
def get_argnames(func): func = getattr(func, '__original__', None) or unwrap(func) return func.__code__.co_varnames[:func.__code__.co_argcount]
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L112-L114
29
[ 0, 1, 2 ]
100
[]
0
true
58.181818
3
2
100
0
def get_argnames(func): func = getattr(func, '__original__', None) or unwrap(func) return func.__code__.co_varnames[:func.__code__.co_argcount]
20,041
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
arggetter
(func, _cache={})
return get_arg
116
144
def arggetter(func, _cache={}): if func in _cache: return _cache[func] original = getattr(func, '__original__', None) or unwrap(func) argnames = get_argnames(original) indexes = dict((name, i) for i, name in enumerate(argnames)) defaults_tuple = original.__defaults__ if defaults_tuple: defaults = dict(zip(argnames[-len(defaults_tuple):], defaults_tuple)) else: defaults = {} def get_arg(name, args, kwargs): if name not in indexes: raise TypeError("%s() doesn't have argument named %s" % (func.__name__, name)) else: index = indexes[name] if index < len(args): return args[index] elif name in kwargs: return kwargs[name] elif name in defaults: return defaults[name] else: raise TypeError("%s() missing required argument: '%s'" % (func.__name__, name)) _cache[func] = get_arg return get_arg
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L116-L144
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 17, 18, 19, 20, 22, 23, 25, 26, 27, 28 ]
86.206897
[ 21 ]
3.448276
false
58.181818
29
9
96.551724
0
def arggetter(func, _cache={}): if func in _cache: return _cache[func] original = getattr(func, '__original__', None) or unwrap(func) argnames = get_argnames(original) indexes = dict((name, i) for i, name in enumerate(argnames)) defaults_tuple = original.__defaults__ if defaults_tuple: defaults = dict(zip(argnames[-len(defaults_tuple):], defaults_tuple)) else: defaults = {} def get_arg(name, args, kwargs): if name not in indexes: raise TypeError("%s() doesn't have argument named %s" % (func.__name__, name)) else: index = indexes[name] if index < len(args): return args[index] elif name in kwargs: return kwargs[name] elif name in defaults: return defaults[name] else: raise TypeError("%s() missing required argument: '%s'" % (func.__name__, name)) _cache[func] = get_arg return get_arg
20,042
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
update_wrapper
(wrapper, wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES)
return wrapper
275
296
def update_wrapper(wrapper, wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES): for attr in assigned: try: value = getattr(wrapped, attr) except AttributeError: pass else: setattr(wrapper, attr, value) for attr in updated: getattr(wrapper, attr).update(getattr(wrapped, attr, {})) # Set it after to not gobble it in __dict__ update wrapper.__wrapped__ = wrapped # Set an original ref for faster and more convenient access wrapper.__original__ = getattr(wrapped, '__original__', None) or unwrap(wrapped) # Return the wrapper so this can be used as a decorator via partial() return wrapper
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L275-L296
29
[ 0, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
81.818182
[]
0
false
58.181818
22
5
100
0
def update_wrapper(wrapper, wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES): for attr in assigned: try: value = getattr(wrapped, attr) except AttributeError: pass else: setattr(wrapper, attr, value) for attr in updated: getattr(wrapper, attr).update(getattr(wrapped, attr, {})) # Set it after to not gobble it in __dict__ update wrapper.__wrapped__ = wrapped # Set an original ref for faster and more convenient access wrapper.__original__ = getattr(wrapped, '__original__', None) or unwrap(wrapped) # Return the wrapper so this can be used as a decorator via partial() return wrapper
20,043
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
wraps
(wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES)
return partial(update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated)
An utility to pass function metadata from wrapped function to a wrapper. Copies all function attributes including ``__name__``, ``__module__`` and ``__doc__``. In addition adds ``__wrapped__`` attribute referring to the wrapped function and ``__original__`` attribute referring to innermost wrapped one. Mostly used to create decorators:: def some_decorator(func): @wraps(func) def wrapper(*args, **kwargs): do_something(*args, **kwargs) return func(*args, **kwargs) return wrapper But see also :func:`@decorator<decorator>` for that. This is extended version of :func:`functools.wraps`.
An utility to pass function metadata from wrapped function to a wrapper. Copies all function attributes including ``__name__``, ``__module__`` and ``__doc__``.
298
322
def wraps(wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES): """ An utility to pass function metadata from wrapped function to a wrapper. Copies all function attributes including ``__name__``, ``__module__`` and ``__doc__``. In addition adds ``__wrapped__`` attribute referring to the wrapped function and ``__original__`` attribute referring to innermost wrapped one. Mostly used to create decorators:: def some_decorator(func): @wraps(func) def wrapper(*args, **kwargs): do_something(*args, **kwargs) return func(*args, **kwargs) return wrapper But see also :func:`@decorator<decorator>` for that. This is extended version of :func:`functools.wraps`. """ return partial(update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L298-L322
29
[ 0, 22, 23, 24 ]
16
[]
0
false
58.181818
25
1
100
18
def wraps(wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES): return partial(update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated)
20,044
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
Call.__init__
(self, func, args, kwargs)
61
62
def __init__(self, func, args, kwargs): self._func, self._args, self._kwargs = func, args, kwargs
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L61-L62
29
[ 0, 1 ]
100
[]
0
true
58.181818
2
1
100
0
def __init__(self, func, args, kwargs): self._func, self._args, self._kwargs = func, args, kwargs
20,045
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
Call.__call__
(self, *a, **kw)
64
68
def __call__(self, *a, **kw): if not a and not kw: return self._func(*self._args, **self._kwargs) else: return self._func(*(self._args + a), **dict(self._kwargs, **kw))
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L64-L68
29
[ 0, 1, 2 ]
60
[ 4 ]
20
false
58.181818
5
3
80
0
def __call__(self, *a, **kw): if not a and not kw: return self._func(*self._args, **self._kwargs) else: return self._func(*(self._args + a), **dict(self._kwargs, **kw))
20,046
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
Call.__getattr__
(self, name)
70
75
def __getattr__(self, name): try: res = self.__dict__[name] = arggetter(self._func)(name, self._args, self._kwargs) return res except TypeError as e: raise AttributeError(*e.args)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L70-L75
29
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
58.181818
6
2
100
0
def __getattr__(self, name): try: res = self.__dict__[name] = arggetter(self._func)(name, self._args, self._kwargs) return res except TypeError as e: raise AttributeError(*e.args)
20,047
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
Call.__str__
(self)
return "%s(%s)" % (func, args)
77
80
def __str__(self): func = getattr(self._func, '__qualname__', str(self._func)) args = ", ".join(list(map(str, self._args)) + ["%s=%s" % t for t in self._kwargs.items()]) return "%s(%s)" % (func, args)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L77-L80
29
[ 0 ]
25
[ 1, 2, 3 ]
75
false
58.181818
4
2
25
0
def __str__(self): func = getattr(self._func, '__qualname__', str(self._func)) args = ", ".join(list(map(str, self._args)) + ["%s=%s" % t for t in self._kwargs.items()]) return "%s(%s)" % (func, args)
20,048
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/decorators.py
Call.__repr__
(self)
return "<Call %s>" % self
82
83
def __repr__(self): return "<Call %s>" % self
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/decorators.py#L82-L83
29
[ 0 ]
50
[ 1 ]
50
false
58.181818
2
1
50
0
def __repr__(self): return "<Call %s>" % self
20,049
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/objects.py
wrap_prop
(ctx)
return decorator
Wrap a property accessors with a context manager
Wrap a property accessors with a context manager
38
63
def wrap_prop(ctx): """Wrap a property accessors with a context manager""" def decorator(prop): class WrapperProp(object): def __repr__(self): return repr(prop) def __get__(self, instance, type=None): if instance is None: return self with ctx: return prop.__get__(instance, type) if hasattr(prop, '__set__'): def __set__(self, name, value): with ctx: return prop.__set__(name, value) if hasattr(prop, '__del__'): def __del__(self, name): with ctx: return prop.__del__(name) return WrapperProp() return decorator
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/objects.py#L38-L63
29
[ 0, 1, 2, 3, 4, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 23, 24, 25 ]
80.769231
[ 5, 9, 20, 21, 22 ]
19.230769
false
85.507246
26
12
80.769231
1
def wrap_prop(ctx): def decorator(prop): class WrapperProp(object): def __repr__(self): return repr(prop) def __get__(self, instance, type=None): if instance is None: return self with ctx: return prop.__get__(instance, type) if hasattr(prop, '__set__'): def __set__(self, name, value): with ctx: return prop.__set__(name, value) if hasattr(prop, '__del__'): def __del__(self, name): with ctx: return prop.__del__(name) return WrapperProp() return decorator
20,050
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/objects.py
monkey
(cls, name=None)
return decorator
Monkey patches class or module by adding to it decorated function. Anything overwritten could be accessed via .original attribute of decorated object.
Monkey patches class or module by adding to it decorated function.
66
83
def monkey(cls, name=None): """ Monkey patches class or module by adding to it decorated function. Anything overwritten could be accessed via .original attribute of decorated object. """ assert isclass(cls) or ismodule(cls), "Attempting to monkey patch non-class and non-module" def decorator(value): func = getattr(value, 'fget', value) # Support properties func_name = name or cut_prefix(func.__name__, '%s__' % cls.__name__) func.__name__ = func_name func.original = getattr(cls, func_name, None) setattr(cls, func_name, value) return value return decorator
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/objects.py#L66-L83
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
100
[]
0
true
85.507246
18
5
100
3
def monkey(cls, name=None): assert isclass(cls) or ismodule(cls), "Attempting to monkey patch non-class and non-module" def decorator(value): func = getattr(value, 'fget', value) # Support properties func_name = name or cut_prefix(func.__name__, '%s__' % cls.__name__) func.__name__ = func_name func.original = getattr(cls, func_name, None) setattr(cls, func_name, value) return value return decorator
20,051
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/objects.py
cached_property.__init__
(self, fget)
21
23
def __init__(self, fget): self.fget = fget self.__doc__ = getattr(fget, '__doc__')
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/objects.py#L21-L23
29
[ 0, 1, 2 ]
100
[]
0
true
85.507246
3
1
100
0
def __init__(self, fget): self.fget = fget self.__doc__ = getattr(fget, '__doc__')
20,052
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/objects.py
cached_property.__get__
(self, instance, type=None)
return res
25
29
def __get__(self, instance, type=None): if instance is None: return self res = instance.__dict__[self.fget.__name__] = self.fget(instance) return res
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/objects.py#L25-L29
29
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
85.507246
5
2
100
0
def __get__(self, instance, type=None): if instance is None: return self res = instance.__dict__[self.fget.__name__] = self.fget(instance) return res
20,053
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/objects.py
namespace_meta.__new__
(cls, name, bases, attrs)
return super(namespace_meta, cls).__new__(cls, name, bases, attrs)
90
92
def __new__(cls, name, bases, attrs): attrs = walk_values(iffy(callable, staticmethod), attrs) return super(namespace_meta, cls).__new__(cls, name, bases, attrs)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/objects.py#L90-L92
29
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
85.507246
3
1
33.333333
0
def __new__(cls, name, bases, attrs): attrs = walk_values(iffy(callable, staticmethod), attrs) return super(namespace_meta, cls).__new__(cls, name, bases, attrs)
20,054
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/objects.py
LazyObject.__init__
(self, init)
107
108
def __init__(self, init): self.__dict__['_init'] = init
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/objects.py#L107-L108
29
[ 0, 1 ]
100
[]
0
true
85.507246
2
1
100
0
def __init__(self, init): self.__dict__['_init'] = init
20,055
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/objects.py
LazyObject._setup
(self)
110
113
def _setup(self): obj = self._init() object.__setattr__(self, '__class__', obj.__class__) object.__setattr__(self, '__dict__', obj.__dict__)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/objects.py#L110-L113
29
[ 0, 1, 2, 3 ]
100
[]
0
true
85.507246
4
1
100
0
def _setup(self): obj = self._init() object.__setattr__(self, '__class__', obj.__class__) object.__setattr__(self, '__dict__', obj.__dict__)
20,056
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/objects.py
LazyObject.__getattr__
(self, name)
return getattr(self, name)
115
117
def __getattr__(self, name): self._setup() return getattr(self, name)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/objects.py#L115-L117
29
[ 0, 1, 2 ]
100
[]
0
true
85.507246
3
1
100
0
def __getattr__(self, name): self._setup() return getattr(self, name)
20,057
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/objects.py
LazyObject.__setattr__
(self, name, value)
return setattr(self, name, value)
119
121
def __setattr__(self, name, value): self._setup() return setattr(self, name, value)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/objects.py#L119-L121
29
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
85.507246
3
1
33.333333
0
def __setattr__(self, name, value): self._setup() return setattr(self, name, value)
20,058
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/calc.py
memoize
(*args, **kwargs)
return _memory_decorator({}, key_func)
@memoize(key_func=None). Makes decorated function memoize its results. If key_func is specified uses key_func(*func_args, **func_kwargs) as memory key. Otherwise uses args + tuple(sorted(kwargs.items())) Exposes its memory via .memory attribute.
@memoize(key_func=None). Makes decorated function memoize its results.
20
36
def memoize(*args, **kwargs): """@memoize(key_func=None). Makes decorated function memoize its results. If key_func is specified uses key_func(*func_args, **func_kwargs) as memory key. Otherwise uses args + tuple(sorted(kwargs.items())) Exposes its memory via .memory attribute. """ if args: assert len(args) == 1 assert not kwargs return memoize()(args[0]) key_func = kwargs.pop('key_func', None) if kwargs: raise TypeError('memoize() got unexpected keyword arguments: %s', ', '.join(kwargs)) return _memory_decorator({}, key_func)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/calc.py#L20-L36
29
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16 ]
94.117647
[ 14 ]
5.882353
false
94.285714
17
5
94.117647
6
def memoize(*args, **kwargs): if args: assert len(args) == 1 assert not kwargs return memoize()(args[0]) key_func = kwargs.pop('key_func', None) if kwargs: raise TypeError('memoize() got unexpected keyword arguments: %s', ', '.join(kwargs)) return _memory_decorator({}, key_func)
20,059
Suor/funcy
5f23815f224e595b8a54822bcb330cd31a799c78
funcy/calc.py
cache
(timeout, key_func=None)
return _memory_decorator(CacheMemory(timeout), key_func)
Caches a function results for timeout seconds.
Caches a function results for timeout seconds.
41
46
def cache(timeout, key_func=None): """Caches a function results for timeout seconds.""" if isinstance(timeout, timedelta): timeout = timeout.total_seconds() return _memory_decorator(CacheMemory(timeout), key_func)
https://github.com/Suor/funcy/blob/5f23815f224e595b8a54822bcb330cd31a799c78/project29/funcy/calc.py#L41-L46
29
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
94.285714
6
2
100
1
def cache(timeout, key_func=None): if isinstance(timeout, timedelta): timeout = timeout.total_seconds() return _memory_decorator(CacheMemory(timeout), key_func)
20,060