Commit Graph

76 Commits

Author SHA1 Message Date
Benjamin Peterson
7b24b27302 merge 3.5 (#27812) 2016-09-05 10:40:34 -07:00
Benjamin Peterson
bdddb11b0e clear out f_gen during generator finalization (closes #27812)
Patch from Armin Rigo.
2016-09-05 10:39:57 -07:00
Benjamin Peterson
98020812e6 merge 3.5 (closes #27811) 2016-09-05 10:16:31 -07:00
Benjamin Peterson
2f40ed4b94 do not allow _PyGen_Finalize to fail (closes #27811)
Patch from Armin Rigo.
2016-09-05 10:14:54 -07:00
Yury Selivanov
711d25db48 Merge 3.5 (issue #27243) 2016-06-09 15:13:16 -04:00
Yury Selivanov
a6f6edbda8 Issue #27243: Fix __aiter__ protocol 2016-06-09 15:08:31 -04:00
Serhiy Storchaka
b0f80b0312 Issue #26647: Python interpreter now uses 16-bit wordcode instead of bytecode.
Patch by Demur Rumed.
2016-05-24 09:15:14 +03:00
Serhiy Storchaka
ec39756960 Issue #22570: Renamed Py_SETREF to Py_XSETREF. 2016-04-06 09:50:03 +03:00
Yury Selivanov
d2dc15b26b Merge 3.5 (issue #25888) 2016-03-02 11:31:06 -05:00
Yury Selivanov
c724bae51c coroutines: Error when awaiting on coroutine that's being awaited
Issue #25888
2016-03-02 11:30:46 -05:00
Yury Selivanov
3e48b38dff Merge 3.5 (issue #25887) 2016-02-13 18:00:31 -05:00
Yury Selivanov
77c96813ab Issue #25887: Raise a RuntimeError when a coroutine is awaited more than once. 2016-02-13 17:59:05 -05:00
Martin Panter
7e3a91a5fc Issue #26136: Upgrade the generator_stop warning to DeprecationWarning
Patch by Anish Shah.
2016-02-10 04:40:48 +00:00
Serhiy Storchaka
576f132b98 Issue #20440: Cleaning up the code by using Py_SETREF. 2016-01-05 21:27:54 +02:00
Yury Selivanov
e13f8f3cab Issue #24450: Add gi_yieldfrom to generators; cr_await to coroutines.
Patch by Benno Leslie and Yury Selivanov.
2015-07-03 00:23:30 -04:00
Yury Selivanov
66f8828bfc Issue #24439: Improve PEP 492 related docs.
Patch by Martin Panter.
2015-06-24 11:04:15 -04:00
Yury Selivanov
5376ba9630 Issue #24400: Introduce a distinct type for 'async def' coroutines.
Summary of changes:

1. Coroutines now have a distinct, separate from generators
   type at the C level: PyGen_Type, and a new typedef PyCoroObject.
   PyCoroObject shares the initial segment of struct layout with
   PyGenObject, making it possible to reuse existing generators
   machinery.  The new type is exposed as 'types.CoroutineType'.

   As a consequence of having a new type, CO_GENERATOR flag is
   no longer applied to coroutines.

2. Having a separate type for coroutines made it possible to add
   an __await__ method to the type.  Although it is not used by the
   interpreter (see details on that below), it makes coroutines
   naturally (without using __instancecheck__) conform to
   collections.abc.Coroutine and collections.abc.Awaitable ABCs.

   [The __instancecheck__ is still used for generator-based
   coroutines, as we don't want to add __await__ for generators.]

3. Add new opcode: GET_YIELD_FROM_ITER.  The opcode is needed to
   allow passing native coroutines to the YIELD_FROM opcode.

   Before this change, 'yield from o' expression was compiled to:

      (o)
      GET_ITER
      LOAD_CONST
      YIELD_FROM

   Now, we use GET_YIELD_FROM_ITER instead of GET_ITER.

   The reason for adding a new opcode is that GET_ITER is used
   in some contexts (such as 'for .. in' loops) where passing
   a coroutine object is invalid.

4. Add two new introspection functions to the inspec module:
   getcoroutinestate(c) and getcoroutinelocals(c).

5. inspect.iscoroutine(o) is updated to test if 'o' is a native
   coroutine object.  Before this commit it used abc.Coroutine,
   and it was requested to update inspect.isgenerator(o) to use
   abc.Generator; it was decided, however, that inspect functions
   should really be tailored for checking for native types.

6. sys.set_coroutine_wrapper(w) API is updated to work with only
   native coroutines.  Since types.coroutine decorator supports
   any type of callables now, it would be confusing that it does
   not work for all types of coroutines.

7. Exceptions logic in generators C implementation was updated
   to raise clearer messages for coroutines:

   Before: TypeError("generator raised StopIteration")
   After: TypeError("coroutine raised StopIteration")
2015-06-22 12:19:30 -04:00
Yury Selivanov
6ef059097c Issue 24017: Drop getawaitablefunc and friends in favor of unaryfunc. 2015-05-28 11:21:31 -04:00
Yury Selivanov
683333955a Issue 24237: Raise PendingDeprecationWarning per PEP 479
Raise PendingDeprecationWarning when generator raises StopIteration
and no __future__ import is used.  Fix offenders in the stdlib
and tests.

See also issue 22906.
Thanks to Nick Coghlan and Berker Peksag for reviews.
2015-05-22 11:16:47 -04:00
Serhiy Storchaka
e79ec70801 Issue #24257: Fixed incorrect uses of PyObject_IsInstance().
Fixed segmentation fault in sqlite3.Row constructor with faked cursor type.
Fixed system error in the comparison of faked types.SimpleNamespace.
2015-05-22 11:13:20 +03:00
Serhiy Storchaka
08d230a540 Issue #24257: Fixed incorrect uses of PyObject_IsInstance().
Fixed segmentation fault in sqlite3.Row constructor with faked cursor type.
Fixed system error in the comparison of faked types.SimpleNamespace.
2015-05-22 11:02:49 +03:00
Yury Selivanov
df52e67d85 Fix warnings for gen_get_iter() 2015-05-11 23:23:05 -04:00
Yury Selivanov
7544508f02 PEP 0492 -- Coroutines with async and await syntax. Issue #24017. 2015-05-11 22:57:16 -04:00
Yury Selivanov
18c30a29f8 Issue #22906: Do incref before SetCause/SetContext 2015-05-10 15:09:46 -04:00
Yury Selivanov
80e4dbea0e Issue 22906: Increment refcount after PyException_SetContext 2015-05-09 14:04:17 -04:00
Yury Selivanov
8170e8c0d1 PEP 479: Change StopIteration handling inside generators.
Closes issue #22906.
2015-05-09 11:44:30 -04:00
Antoine Pitrou
7503509f19 Issue #23996: Avoid a crash when a delegated generator raises an unnormalized StopIteration exception. Patch by Stefan Behnel. 2015-04-26 18:48:16 +02:00
Antoine Pitrou
7403e91630 Issue #23996: Avoid a crash when a delegated generator raises an unnormalized StopIteration exception. Patch by Stefan Behnel. 2015-04-26 18:46:40 +02:00
Antoine Pitrou
667f545e03 Issue #21938: simplify gen_iternext() 2014-07-08 18:43:23 -04:00
Victor Stinner
40ee30181f Issue #21205: Add a new `__qualname__` attribute to generator, the qualified
name, and use it in the representation of a generator (``repr(gen)``). The
default name of the generator (``__name__`` attribute) is now get from the
function instead of the code. Use ``gen.gi_code.co_name`` to get the name of
the code.
2014-06-16 15:59:28 +02:00
Antoine Pitrou
58720d6145 Issue #17934: Add a clear() method to frame objects, to help clean up expensive details (local variables) and break reference cycles. 2013-08-05 23:26:40 +02:00
Antoine Pitrou
796564c27b Issue #18112: PEP 442 implementation (safe object finalization). 2013-07-30 19:59:21 +02:00
Antoine Pitrou
9396356948 Backout c89febab4648 following private feedback by Guido.
(Issue #17807: Generators can now be finalized even when they are part of a reference cycle)
2013-05-14 20:37:52 +02:00
Antoine Pitrou
04e70d19e7 Issue #17807: Generators can now be finalized even when they are part of a reference cycle. 2013-05-08 18:12:35 +02:00
Benjamin Peterson
c9314d9e08 don't run frame if it has no stack (closes #17669) 2013-04-10 17:00:56 -04:00
Nick Coghlan
5b0dac12b8 Issue #13783: PEP 380 cleanup part 2, using the new identifier APIs in the generator implementation 2012-06-17 15:45:11 +10:00
Nick Coghlan
c40bc09942 Issue #13783: the PEP 380 implementation no longer expands the public C API 2012-06-17 15:15:49 +10:00
Benjamin Peterson
9cd8853d45 merge 3.2 (#14717) 2012-05-03 18:44:33 -04:00
Benjamin Peterson
ab3da290fe close() doesn't take any args (closes #14717) 2012-05-03 18:44:09 -04:00
Benjamin Peterson
f50af113ab space 2012-03-15 15:37:54 -05:00
Benjamin Peterson
2afe6aeae8 perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
This allows generators that are using yield from to be seen by debuggers. It
also kills the f_yieldfrom field on frame objects.

Patch mostly from Mark Shannon with a few tweaks by me.
2012-03-15 15:37:39 -05:00
Benjamin Peterson
657e9ebef5 make gi_running a boolean 2012-03-07 18:17:03 -06:00
Benjamin Peterson
9fc309083a indicate we're not running as we leave this block 2012-03-07 18:11:31 -06:00
Benjamin Peterson
099a78fe6d make delegating generators say they running (closes #14220) 2012-03-07 17:57:04 -06:00
Amaury Forgeot d'Arc
e557da804a Fix a crash when the return value of a subgenerator is a temporary
object (with a refcount of 1)
2012-01-13 21:06:12 +01:00
Nick Coghlan
1f7ce62bd6 Implement PEP 380 - 'yield from' (closes #11682) 2012-01-13 21:43:40 +10:00
Benjamin Peterson
dc37ce95e8 merge 3.2 2011-10-19 16:58:15 -04:00
Benjamin Peterson
9d9141f5db adjust braces a bit 2011-10-19 16:57:40 -04:00
Antoine Pitrou
cf28eacafe Issue #13188: When called without an explicit traceback argument,
generator.throw() now gets the traceback from the passed exception's
``__traceback__`` attribute.  Patch by Petri Lehtinen.
2011-10-18 16:42:55 +02:00
Antoine Pitrou
551ba20e8e Issue #13188: When called without an explicit traceback argument,
generator.throw() now gets the traceback from the passed exception's
`__traceback__` attribute.  Patch by Petri Lehtinen.
2011-10-18 16:40:50 +02:00