Revert None deafult for aiter/anext and add whatsnew entry

This commit is contained in:
Justin Wang 2020-12-21 13:13:35 -05:00
parent 8b8a689128
commit 894600d8e2
4 changed files with 19 additions and 11 deletions

View File

@ -157,6 +157,11 @@ Other Language Changes
* Assignment expressions can now be used unparenthesized within set literals
and set comprehensions, as well as in sequence indexes (but not slices).
* Two new builtin functions -- :func:`aiter` and :func:`anext` have been added
to provide asynchronous counterparts to :func:`iter` and :func:`next`,
respectively.
(Contributed by Joshua Bronson, Justin Wang and Daniel Pope in :issue:`31861`)
New Modules
===========

View File

@ -3814,6 +3814,9 @@ class TestSignatureDefinitions(unittest.TestCase):
needs_groups = {"range", "slice", "dir", "getattr",
"next", "iter", "vars"}
no_signature |= needs_groups
# These have unpresentable parameter default values of NULL
needs_null = {"aiter", "anext"}
no_signature |= needs_null
# These need PEP 457 groups or a signature change to accept None
needs_semantic_update = {"round"}
no_signature |= needs_semantic_update

View File

@ -1539,7 +1539,7 @@ In the second form, the callable is called until it returns the sentinel.");
aiter as builtin_aiter
aiterable: object
sentinel: object = None
sentinel: object = NULL
/
Return an async iterator for an async iterable object.
@ -1547,9 +1547,9 @@ Return an async iterator for an async iterable object.
static PyObject *
builtin_aiter_impl(PyObject *module, PyObject *aiterable, PyObject *sentinel)
/*[clinic end generated code: output=ea120e90169d9f32 input=586f672fb18a94a5]*/
/*[clinic end generated code: output=ea120e90169d9f32 input=a12efceda1863b3c]*/
{
if (sentinel == Py_None) {
if (sentinel == NULL) {
return PyObject_GetAiter(aiterable);
}
@ -1566,7 +1566,7 @@ builtin_aiter_impl(PyObject *module, PyObject *aiterable, PyObject *sentinel)
anext as builtin_anext
aiterator: object
default: object = None
default: object = NULL
/
Return the next item from the async iterator.
@ -1575,7 +1575,7 @@ Return the next item from the async iterator.
static PyObject *
builtin_anext_impl(PyObject *module, PyObject *aiterator,
PyObject *default_value)
/*[clinic end generated code: output=f02c060c163a81fa input=6051f80000c06306]*/
/*[clinic end generated code: output=f02c060c163a81fa input=699d11f4e38eca24]*/
{
PyTypeObject *t;
PyObject *awaitable;
@ -1589,7 +1589,7 @@ builtin_anext_impl(PyObject *module, PyObject *aiterator,
}
awaitable = (*t->tp_as_async->am_anext)(aiterator);
if (default_value == Py_None) {
if (default_value == NULL) {
return awaitable;
}

View File

@ -531,7 +531,7 @@ PyDoc_STRVAR(builtin_hex__doc__,
{"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__},
PyDoc_STRVAR(builtin_aiter__doc__,
"aiter($module, aiterable, sentinel=None, /)\n"
"aiter($module, aiterable, sentinel=<unrepresentable>, /)\n"
"--\n"
"\n"
"Return an async iterator for an async iterable object.");
@ -547,7 +547,7 @@ builtin_aiter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *aiterable;
PyObject *sentinel = Py_None;
PyObject *sentinel = NULL;
if (!_PyArg_CheckPositional("aiter", nargs, 1, 2)) {
goto exit;
@ -565,7 +565,7 @@ exit:
}
PyDoc_STRVAR(builtin_anext__doc__,
"anext($module, aiterator, default=None, /)\n"
"anext($module, aiterator, default=<unrepresentable>, /)\n"
"--\n"
"\n"
"Return the next item from the async iterator.");
@ -582,7 +582,7 @@ builtin_anext(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *aiterator;
PyObject *default_value = Py_None;
PyObject *default_value = NULL;
if (!_PyArg_CheckPositional("anext", nargs, 1, 2)) {
goto exit;
@ -899,4 +899,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
/*[clinic end generated code: output=02b80d529a5c972b input=a9049054013a1b77]*/
/*[clinic end generated code: output=b5248d88ee495198 input=a9049054013a1b77]*/