From a9ae6dbb7fe179c5aa355a19b1358cad906bdd97 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Thu, 30 Jul 2020 22:03:26 +0100 Subject: [PATCH] core: add error count to stats helper --- my/core/common.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/my/core/common.py b/my/core/common.py index d9bce98..af51c48 100644 --- a/my/core/common.py +++ b/my/core/common.py @@ -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, }