cpython/Objects
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
..
clinic Issue #24007: Argument Clinic now writes the format of PyArg_Parse*() at the 2015-04-24 00:40:51 +03:00
stringlib Fixed typos in comments. 2015-05-18 22:20:18 +03:00
README Issue #18093: Factor out the programs that embed the runtime 2014-07-25 21:52:14 +10:00
abstract.c merge 2015-05-17 14:47:00 -07:00
accu.c Issue #14387: Do not include accu.h from Python.h. 2012-03-22 14:38:16 +01:00
boolobject.c Recorded merge of revisions 81032 via svnmerge from 2010-05-09 16:14:21 +00:00
bytearrayobject.c Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(), 2015-05-30 17:48:19 +03:00
bytes_methods.c Issue #22896: Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer() 2015-02-03 01:25:42 +02:00
bytesobject.c Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(), 2015-05-30 17:48:19 +03:00
capsule.c Issue #2443: Added a new macro, Py_VA_COPY, which is equivalent to C99 2010-08-11 17:31:17 +00:00
cellobject.c Recorded merge of revisions 81032 via svnmerge from 2010-05-09 16:14:21 +00:00
classobject.c Removed unintentional trailing spaces in non-external and non-generated C files. 2015-03-18 21:53:15 +02:00
codeobject.c Issue #18874: PyCode_New() now ensures that the filename is a ready Unicode 2013-10-10 15:55:14 +02:00
complexobject.c Issue #22896: Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer() 2015-02-03 01:25:42 +02:00
descrobject.c Fixed indentation of Python examples in C comments. 2015-06-11 00:07:47 +03:00
dict-common.h Issue #16991: Add a C implementation of collections.OrderedDict. 2015-05-29 22:21:39 -06:00
dictnotes.txt Issue #15055: update dictnotes.txt. Patch by Mark Shannon. 2012-06-24 21:03:45 +02:00
dictobject.c Issue #16991: Add a C implementation of collections.OrderedDict. 2015-05-29 22:21:39 -06:00
enumobject.c Issue #14288: Serialization support for builtin iterators. 2012-04-03 10:49:41 +00:00
exceptions.c PEP 0492 -- Coroutines with async and await syntax. Issue #24017. 2015-05-11 22:57:16 -04:00
fileobject.c stdprinter_write(): mention the encoding 2015-03-24 13:40:29 +01:00
floatobject.c Issue 19933: Provide default argument for ndigits in round. Patch by Vajrasky Kok. 2015-04-15 16:10:59 -04:00
frameobject.c PEP 0492 -- Coroutines with async and await syntax. Issue #24017. 2015-05-11 22:57:16 -04:00
funcobject.c Issue #18520: Fix PyFunction_NewWithQualName() error handling 2013-07-22 23:04:55 +02:00
genobject.c Issue #24400: Introduce a distinct type for 'async def' coroutines. 2015-06-22 12:19:30 -04:00
iterobject.c Issue #23985: Fixed integer overflow in iterator object. Patch by 2015-05-21 20:51:53 +03:00
listobject.c merge 3.4 (#24044) 2015-04-23 17:06:45 -04:00
listsort.txt Various clarifications based on feedback & questions over the years. 2013-08-24 15:15:19 -05:00
lnotab_notes.txt
longobject.c Issue #22486: Added the math.gcd() function. The fractions.gcd() function now is 2015-05-13 00:19:51 +03:00
memoryobject.c Implements issue #9951: Adds a hex() method to bytes, bytearray, & memoryview. 2015-04-25 23:22:26 +00:00
methodobject.c Merge 3.4 2015-04-27 17:49:16 +03:00
moduleobject.c Issue #24268: Address some PEP 489 refleaks 2015-05-24 01:03:46 +10:00
namespaceobject.c Issue #24257: Fixed incorrect uses of PyObject_IsInstance(). 2015-05-22 11:02:49 +03:00
object.c Issue #24400: Introduce a distinct type for 'async def' coroutines. 2015-06-22 12:19:30 -04:00
obmalloc.c Issue #23450: Fixed possible integer overflows. 2015-02-16 20:52:17 +02:00
odictobject.c repair my irrational excuberance 2015-06-07 00:00:42 -05:00
rangeobject.c Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(), 2015-05-30 17:48:19 +03:00
setobject.c Reverting my previous commit. 2015-05-30 10:57:56 -04:00
sliceobject.c Make Ellipsis and NotImplemented picklable through the reduce protocol. 2013-11-24 02:53:45 -08:00
structseq.c Issue #18520: Add a new PyStructSequence_InitType2() function, same than 2013-07-22 22:24:54 +02:00
tupleobject.c Issue #23629: Fix the default __sizeof__ implementation for variable-sized objects. 2015-03-10 22:35:24 +01:00
typeobject.c Fixed indentation of Python examples in C comments. 2015-06-11 00:07:47 +03:00
typeslots.inc add Py_tp_finalize slot (closes #24345) 2015-06-01 10:12:48 -05:00
typeslots.py PEP 0492 -- Coroutines with async and await syntax. Issue #24017. 2015-05-11 22:57:16 -04:00
unicodectype.c Removed unintentional trailing spaces in non-external and non-generated C files. 2015-03-18 21:53:15 +02:00
unicodeobject.c Issue #24284: The startswith and endswith methods of the str class no longer 2015-05-31 09:15:51 +03:00
unicodetype_db.h upgrade to unicode 7.0.0 2014-07-06 13:04:20 -07:00
weakrefobject.c Issue #23783: Fixed memory leak in PyObject_ClearWeakRefs() in case of 2015-03-30 09:52:29 +03:00

README

Source files for various builtin objects