diff --git a/satella/coding/sequences/iterators.py b/satella/coding/sequences/iterators.py index ab87833d60dc7e560890c39850b3495675296f5d..322c34649e0578e1a36479a5cc3afdd8550e1895 100644 --- a/satella/coding/sequences/iterators.py +++ b/satella/coding/sequences/iterators.py @@ -12,29 +12,32 @@ IteratorOrIterable = tp.Union[tp.Iterator[T], tp.Iterable[T]] @for_argument(iter) -@silence_excs(StopIteration) def even(sq: IteratorOrIterable) -> tp.Iterator[T]: """ Return only elements with even indices in this iterable (first element will be returned, as indices are counted from 0) """ - while True: - yield next(sq) - next(sq) + try: + while True: + yield next(sq) + next(sq) + except StopIteration: + return @for_argument(iter) -@silence_excs(StopIteration) def odd(sq: IteratorOrIterable) -> tp.Iterator[T]: """ Return only elements with odd indices in this iterable. """ - while True: - next(sq) - yield next(sq) + try: + while True: + next(sq) + yield next(sq) + except StopIteration: + return -@silence_excs(StopIteration) def count(sq: IteratorOrIterable, start: tp.Optional[int] = None, step: int = 1) -> tp.Iterator[int]: """ Return a sequence of integers, for each entry in the sequence with provided step. diff --git a/tests/test_instrumentation/test_metrics/test_metrics.py b/tests/test_instrumentation/test_metrics/test_metrics.py index b2f5c89a5bd1adc4b4409d629ddc397de316e9d7..d02ea89ac0b701ab5d4a85a0aa11fced5f1dfe68 100644 --- a/tests/test_instrumentation/test_metrics/test_metrics.py +++ b/tests/test_instrumentation/test_metrics/test_metrics.py @@ -138,7 +138,6 @@ class TestMetric(unittest.TestCase): self.assertTrue(inspect.isgeneratorfunction(generator)) self.assertGreaterEqual(next(iter(my_metric.to_metric_data().values)).value, 1) - def test_quantile_context_manager(self): metric = getMetric('test_metric', 'summary', quantiles=[0.5]) with metric.measure():