From ed4b6c409f19e67ec8e9d0b3f1090aa170ea3fea Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 31 Oct 2020 17:00:01 +0000 Subject: [PATCH] doctor & stat improvements - doctor: log when there is no stats() function and suggest to use it - check that stats() result isn't None - warn when there is not data in the iterable --- my/core/__main__.py | 3 +++ my/core/common.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/my/core/__main__.py b/my/core/__main__.py index 7b402ad..ca3240d 100644 --- a/my/core/__main__.py +++ b/my/core/__main__.py @@ -212,10 +212,13 @@ def modules_check(args): info(f'{color.GREEN}OK{color.RESET} : {m:<50}') stats = get_stats(m) if stats is None: + eprint(" - no 'stats' function, can't check the data") + # todo point to a readme on the module structure or something? continue try: res = stats() + assert res is not None, 'stats() returned None' except Exception as ee: warning(f' - {color.RED}stats:{color.RESET} computing failed{vw}') if verbose: diff --git a/my/core/common.py b/my/core/common.py index 10ecacc..0aeb9a5 100644 --- a/my/core/common.py +++ b/my/core/common.py @@ -403,11 +403,13 @@ def _stat_iterable(it: Iterable[C]) -> Any: from more_itertools import ilen, take, first # todo not sure if there is something in more_itertools to compute this? + total = 0 errors = 0 last = None def funcit(): - nonlocal errors, last + nonlocal errors, last, total for x in it: + total += 1 if isinstance(x, Exception): errors += 1 else: @@ -429,6 +431,10 @@ def _stat_iterable(it: Iterable[C]) -> Any: 'count': count, } + if total == 0: + # not sure but I guess a good balance? wouldn't want to throw early here? + res['warning'] = 'THE ITERABLE RETURNED NO DATA' + if errors > 0: res['errors'] = errors