cpython/Doc/c-api
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
..
abstract.rst Merged revisions 85082 via svnmerge from 2010-09-28 23:41:31 +00:00
allocation.rst Issue #18589: fix hyperlinking of type slots (tp_*) 2013-08-01 21:12:45 +02:00
apiabiversion.rst Remove row-spanning cell, which the Sphinx text writer does not support. 2013-03-16 08:01:49 +01:00
arg.rst Doc clarification / edification on the semantics of the 'w*' format unit. 2015-04-13 11:30:56 -04:00
bool.rst Migrate to Sphinx 1.0 C language constructs. 2010-10-06 10:11:56 +00:00
buffer.rst Whitespace. 2015-02-01 19:46:31 +01:00
bytearray.rst #23088: Clarify null termination of bytes and strings in C API. 2015-05-13 20:31:53 -04:00
bytes.rst #23088: Clarify null termination of bytes and strings in C API. 2015-05-13 20:31:53 -04:00
capsule.rst Migrate to Sphinx 1.0 C language constructs. 2010-10-06 10:11:56 +00:00
cell.rst Migrate to Sphinx 1.0 C language constructs. 2010-10-06 10:11:56 +00:00
code.rst Issue #14090: fix some minor C API problems in default branch (3.3) 2012-06-03 08:07:47 +03:00
codec.rst Issue #19676: Tweak documentation a bit. 2014-11-25 18:59:20 +02:00
complex.rst Issue #13522: Fix _Py_co_pow() documentation 2011-12-18 02:56:18 +01:00
concrete.rst Issue #24400: Introduce a distinct type for 'async def' coroutines. 2015-06-22 12:19:30 -04:00
conversion.rst Fixed documentation of functions with const char* arguments. 2015-06-21 17:11:21 +03:00
coro.rst Issue #24400: Introduce a distinct type for 'async def' coroutines. 2015-06-22 12:19:30 -04:00
datetime.rst Issue #13727: Add 3 macros to access PyDateTime_Delta members: 2012-01-17 21:31:50 +01:00
descriptor.rst Migrate to Sphinx 1.0 C language constructs. 2010-10-06 10:11:56 +00:00
dict.rst Closes #18456: Doc fix: PyDict_Update only works with dict-like objects, not key-value sequences. Patch by priyapappachan. 2014-03-25 09:34:30 +01:00
exceptions.rst Fixed documentation of functions with const char* arguments. 2015-06-21 17:12:16 +03:00
file.rst Issue #1772673: The type of char* arguments now changed to const char*. 2013-10-19 21:03:34 +03:00
float.rst Issue #13522: document error return values of some float and complex C API functions. 2011-12-18 01:25:27 +01:00
function.rst PEP 3155 / issue #13448: Qualified name for classes and functions. 2011-11-25 18:56:07 +01:00
gcsupport.rst Issue #18589: fix hyperlinking of type slots (tp_*) 2013-08-01 21:12:45 +02:00
gen.rst Issue #24400: Introduce a distinct type for 'async def' coroutines. 2015-06-22 12:19:30 -04:00
import.rst Fixed documentation of functions with const char* arguments. 2015-06-21 17:12:16 +03:00
index.rst Introduce support for documenting which C API elements are not part of the stable/limited API. 2013-10-12 19:54:30 +02:00
init.rst Fixed documentation of functions with const char* arguments. 2015-06-21 17:12:16 +03:00
intro.rst Clean up references to the no longer existing PyString_ APIs in our docs. 2013-03-22 13:43:30 -07:00
iter.rst Issue #19005: Fix documentation for PyIter_Next(). 2013-10-09 22:42:46 -07:00
iterator.rst Migrate to Sphinx 1.0 C language constructs. 2010-10-06 10:11:56 +00:00
list.rst Issue #13389: Full garbage collection passes now clear the freelists for 2011-11-15 00:00:12 +01:00
long.rst Issue #1772673: The type of char* arguments now changed to const char*. 2013-10-19 21:03:34 +03:00
mapping.rst Fixed documentation of functions with const char* arguments. 2015-06-21 17:11:21 +03:00
marshal.rst Fixed documentation of functions with const char* arguments. 2015-06-21 17:11:21 +03:00
memory.rst Merge: #23957: fix typo. 2015-04-14 16:42:49 -04:00
memoryview.rst Add PyMemoryView_FromMemory() to whatsnew/3.3. 2012-02-29 17:27:21 +01:00
method.rst Remove duplication. 2011-10-19 10:58:56 +03:00
module.rst PEP 489: Multi-phase extension module initialization 2015-05-23 22:24:10 +10:00
none.rst Migrate to Sphinx 1.0 C language constructs. 2010-10-06 10:11:56 +00:00
number.rst PEP 465: a dedicated infix operator for matrix multiplication (closes #21176) 2014-04-09 23:55:56 -04:00
objbuffer.rst Migrate to Sphinx 1.0 C language constructs. 2010-10-06 10:11:56 +00:00
object.rst Fixed a typo. 2015-05-02 19:24:41 +03:00
objimpl.rst Split C API docs in Py3k branch. 2008-01-20 09:30:57 +00:00
refcounting.rst Migrate to Sphinx 1.0 C language constructs. 2010-10-06 10:11:56 +00:00
reflection.rst Migrate to Sphinx 1.0 C language constructs. 2010-10-06 10:11:56 +00:00
sequence.rst Issue #23081: Document that PySequence_List also accepts iterables. 2015-03-13 02:55:45 +02:00
set.rst Issue 19195: Improved cross-references in C API documentation. 2013-10-09 13:26:17 +03:00
slice.rst Merged revisions 87101,87146,87156,87172,87175,87371,87378,87522-87524,87526-87528,87530-87536,87581 via svnmerge from 2011-02-25 10:03:34 +00:00
stable.rst Introduce support for documenting which C API elements are not part of the stable/limited API. 2013-10-12 19:54:30 +02:00
structures.rst Regenerated pydoc-topics and fixed bad/suspicious doc markup for Python 3.5.0a4. 2015-04-19 13:50:12 -07:00
sys.rst Fixed documentation of functions with const char* arguments. 2015-06-21 17:12:16 +03:00
tuple.rst Merge in all documentation changes since branching 3.4.0rc1. 2014-03-15 21:13:56 -07:00
type.rst Clean up the docs of PyObject_IsSubclass and PyObject_IsInstance, and mention that they call the PEP 3119 methods. 2014-10-06 14:38:53 +02:00
typeobj.rst Issue 24017: Drop getawaitablefunc and friends in favor of unaryfunc. 2015-05-28 11:21:31 -04:00
unicode.rst Fixed documentation of functions with const char* arguments. 2015-06-21 17:12:16 +03:00
utilities.rst Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from 2010-11-26 09:05:43 +00:00
veryhigh.rst Issue #20500: Note other public APIs with the new assertion 2014-02-09 12:00:01 +10:00
weakref.rst demote this to a note 2011-05-31 21:27:41 -05:00