Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: py3.7 Changeset: r98613:cac6a157cae7 Date: 2020-01-31 15:37 +0100 http://bitbucket.org/pypy/pypy/changeset/cac6a157cae7/
Log: generator_stop is not the default diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -163,23 +163,14 @@ self.frame.w_yielding_from = w_delegate def _leak_stopiteration(self, e): - # Check for __future__ generator_stop and conditionally turn - # a leaking StopIteration into RuntimeError (with its cause - # set appropriately). + # turn a leaking StopIteration into RuntimeError (with its cause set + # appropriately). space = self.space - if self.pycode.co_flags & (consts.CO_FUTURE_GENERATOR_STOP | - consts.CO_COROUTINE | - consts.CO_ITERABLE_COROUTINE | - consts.CO_ASYNC_GENERATOR): - e2 = OperationError(space.w_RuntimeError, - space.newtext("%s raised StopIteration" % - self.KIND)) - e2.chain_exceptions_from_cause(space, e) - raise e2 - else: - space.warn(space.newtext("generator '%s' raised StopIteration" - % self.get_qualname()), - space.w_DeprecationWarning) + e2 = OperationError(space.w_RuntimeError, + space.newtext("%s raised StopIteration" % + self.KIND)) + e2.chain_exceptions_from_cause(space, e) + raise e2 def _leak_stopasynciteration(self, e): space = self.space diff --git a/pypy/interpreter/test/apptest_generator.py b/pypy/interpreter/test/apptest_generator.py --- a/pypy/interpreter/test/apptest_generator.py +++ b/pypy/interpreter/test/apptest_generator.py @@ -221,16 +221,6 @@ g = f() assert g.close() is None -def test_close2(): - def f(): - try: - yield 1 - except GeneratorExit: - raise StopIteration - g = f() - next(g) - assert g.close() is None - def test_close3(): def f(): try: @@ -275,21 +265,6 @@ with raises(TypeError): g.send(1) # not started, must send None -def test_generator_explicit_stopiteration(): - def f(): - yield 1 - raise StopIteration - g = f() - assert [x for x in g] == [1] - -def test_generator_propagate_stopiteration(): - def f(): - it = iter([1]) - while 1: - yield next(it) - g = f() - assert [x for x in g] == [1] - def test_generator_restart(): def g(): i = next(me) @@ -325,12 +300,6 @@ assert set(g) == set() assert set(i for i in range(0)) == set() -def test_explicit_stop_iteration_unpackiterable(): - def f(): - yield 1 - raise StopIteration - assert tuple(f()) == (1,) - def test_exception_is_cleared_by_yield(): def f(): try: @@ -826,34 +795,18 @@ assert isinstance(excinfo.value.__context__, ValueError) -def test_past_generator_stop(): - # how it works without 'from __future__' import generator_stop - def f(x): - raise StopIteration +def test_stopiteration_turned_into_runtime_error(): + def badgenerator(x): + if x == 5: + raise StopIteration yield x - with raises(StopIteration): - next(f(5)) - -def test_future_generator_stop(): - d = {} - exec("""from __future__ import generator_stop - -def f(x): - raise StopIteration - yield x -""", d) - f = d['f'] with raises(RuntimeError): - next(f(5)) + next(badgenerator(5)) def test_generator_stop_cause(): - d = {} - exec("""from __future__ import generator_stop - -def gen1(): - yield 42 -""", d) - my_gen = d['gen1']() + def gen1(): + yield 42 + my_gen = gen1() assert next(my_gen) == 42 stop_exc = StopIteration('spam') with raises(RuntimeError) as e: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit