core: add error count to stats helper
This commit is contained in:
parent
92307d5f3d
commit
a9ae6dbb7f
1 changed files with 14 additions and 1 deletions
|
@ -365,7 +365,16 @@ C = TypeVar('C')
|
|||
def stat(func: Callable[[], Iterable[C]]) -> Dict[str, Any]:
|
||||
from more_itertools import ilen, take, first
|
||||
|
||||
it = iter(func())
|
||||
# todo not sure if there is something in more_itertools to compute this?
|
||||
errors = 0
|
||||
def funcit():
|
||||
nonlocal errors
|
||||
for x in func():
|
||||
if isinstance(x, Exception):
|
||||
errors += 1
|
||||
yield x
|
||||
|
||||
it = iter(funcit())
|
||||
res: Any
|
||||
if QUICK_STATS:
|
||||
initial = take(100, it)
|
||||
|
@ -377,6 +386,10 @@ def stat(func: Callable[[], Iterable[C]]) -> Dict[str, Any]:
|
|||
res = ilen(it)
|
||||
|
||||
|
||||
if errors > 0:
|
||||
# todo not sure, but for now ok
|
||||
res = f'{res} ({errors} errors)'
|
||||
|
||||
return {
|
||||
func.__name__: res,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue