Skip to content

Commit 2c3474a

Browse files
1st1pablogsal
andauthored
bpo-45123: PyAiter_Check and PyObject_GetAiter fix & rename. (GH-28194)
Fix PyAiter_Check to only check for the `__anext__` presense (not for `__aiter__`). Rename `PyAiter_Check()` to `PyAIter_Check()`, `PyObject_GetAiter()` -> `PyObject_GetAIter()`. Co-authored-by: Pablo Galindo Salgado <[email protected]>
1 parent eb254b4 commit 2c3474a

File tree

10 files changed

+23
-22
lines changed

10 files changed

+23
-22
lines changed

Doc/c-api/iter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ There are two functions specifically for working with iterators.
1212
Return non-zero if the object *o* supports the iterator protocol, and ``0``
1313
otherwise. This function always succeeds.
1414
15-
.. c:function:: int PyAiter_Check(PyObject *o)
15+
.. c:function:: int PyAIter_Check(PyObject *o)
1616
1717
Returns non-zero if the object 'obj' provides :class:`AsyncIterator`
1818
protocols, and ``0`` otherwise. This function always succeeds.

Doc/c-api/object.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ Object Protocol
358358
iterated.
359359
360360
361-
.. c:function:: PyObject* PyObject_GetAiter(PyObject *o)
361+
.. c:function:: PyObject* PyObject_GetAIter(PyObject *o)
362362
363363
This is the equivalent to the Python expression ``aiter(o)``. Takes an
364364
:class:`AsyncIterable` object and returns an :class:`AsyncIterator` for it.

Doc/data/refcounts.dat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ PyInterpreterState_New:PyInterpreterState*:::
10731073
PyIter_Check:int:::
10741074
PyIter_Check:PyObject*:o:0:
10751075

1076-
PyAiter_Check:int:::
1077-
PyAiter_Check:PyObject*:o:0:
1076+
PyAIter_Check:int:::
1077+
PyAIter_Check:PyObject*:o:0:
10781078

10791079
PyIter_Next:PyObject*::+1:
10801080
PyIter_Next:PyObject*:o:0:
@@ -1700,8 +1700,8 @@ PyObject_GetItem:PyObject*:key:0:
17001700
PyObject_GetIter:PyObject*::+1:
17011701
PyObject_GetIter:PyObject*:o:0:
17021702

1703-
PyObject_GetAiter:PyObject*::+1:
1704-
PyObject_GetAiter:PyObject*:o:0:
1703+
PyObject_GetAIter:PyObject*::+1:
1704+
PyObject_GetAIter:PyObject*:o:0:
17051705

17061706
PyObject_HasAttr:int:::
17071707
PyObject_HasAttr:PyObject*:o:0:

Doc/data/stable_abi.dat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
role,name,added,ifdef_note
2-
function,PyAiter_Check,3.10,
2+
function,PyAIter_Check,3.10,
33
function,PyArg_Parse,3.2,
44
function,PyArg_ParseTuple,3.2,
55
function,PyArg_ParseTupleAndKeywords,3.2,
@@ -491,7 +491,7 @@ function,PyObject_GenericGetAttr,3.2,
491491
function,PyObject_GenericGetDict,3.10,
492492
function,PyObject_GenericSetAttr,3.2,
493493
function,PyObject_GenericSetDict,3.7,
494-
function,PyObject_GetAiter,3.10,
494+
function,PyObject_GetAIter,3.10,
495495
function,PyObject_GetAttr,3.2,
496496
function,PyObject_GetAttrString,3.2,
497497
function,PyObject_GetItem,3.2,

Include/abstract.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
374374
/* Takes an AsyncIterable object and returns an AsyncIterator for it.
375375
This is typically a new iterator but if the argument is an AsyncIterator,
376376
this returns itself. */
377-
PyAPI_FUNC(PyObject *) PyObject_GetAiter(PyObject *);
377+
PyAPI_FUNC(PyObject *) PyObject_GetAIter(PyObject *);
378378

379379
/* Returns non-zero if the object 'obj' provides iterator protocols, and 0 otherwise.
380380
@@ -384,7 +384,7 @@ PyAPI_FUNC(int) PyIter_Check(PyObject *);
384384
/* Returns non-zero if the object 'obj' provides AsyncIterator protocols, and 0 otherwise.
385385
386386
This function always succeeds. */
387-
PyAPI_FUNC(int) PyAiter_Check(PyObject *);
387+
PyAPI_FUNC(int) PyAIter_Check(PyObject *);
388388

389389
/* Takes an iterator object and calls its tp_iternext slot,
390390
returning the next value.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix PyAiter_Check to only check for the __anext__ presence (not for
2+
__aiter__). Rename PyAiter_Check to PyAIter_Check, PyObject_GetAiter ->
3+
PyObject_GetAIter.

Misc/stable_abi.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,9 +2110,9 @@ function _Py_IncRef
21102110
function _Py_DecRef
21112111
added 3.10
21122112
abi_only
2113-
function PyAiter_Check
2113+
function PyAIter_Check
21142114
added 3.10
2115-
function PyObject_GetAiter
2115+
function PyObject_GetAIter
21162116
added 3.10
21172117
data PyExc_EncodingWarning
21182118
added 3.10

Objects/abstract.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,18 +2816,18 @@ PyObject_GetIter(PyObject *o)
28162816
}
28172817

28182818
PyObject *
2819-
PyObject_GetAiter(PyObject *o) {
2819+
PyObject_GetAIter(PyObject *o) {
28202820
PyTypeObject *t = Py_TYPE(o);
28212821
unaryfunc f;
28222822

28232823
if (t->tp_as_async == NULL || t->tp_as_async->am_aiter == NULL) {
2824-
return type_error("'%.200s' object is not an AsyncIterable", o);
2824+
return type_error("'%.200s' object is not an async iterable", o);
28252825
}
28262826
f = t->tp_as_async->am_aiter;
28272827
PyObject *it = (*f)(o);
2828-
if (it != NULL && !PyAiter_Check(it)) {
2828+
if (it != NULL && !PyAIter_Check(it)) {
28292829
PyErr_Format(PyExc_TypeError,
2830-
"aiter() returned non-AsyncIterator of type '%.100s'",
2830+
"aiter() returned not an async iterator of type '%.100s'",
28312831
Py_TYPE(it)->tp_name);
28322832
Py_DECREF(it);
28332833
it = NULL;
@@ -2844,12 +2844,10 @@ PyIter_Check(PyObject *obj)
28442844
}
28452845

28462846
int
2847-
PyAiter_Check(PyObject *obj)
2847+
PyAIter_Check(PyObject *obj)
28482848
{
28492849
PyTypeObject *tp = Py_TYPE(obj);
28502850
return (tp->tp_as_async != NULL &&
2851-
tp->tp_as_async->am_aiter != NULL &&
2852-
tp->tp_as_async->am_aiter != &_PyObject_NextNotImplemented &&
28532851
tp->tp_as_async->am_anext != NULL &&
28542852
tp->tp_as_async->am_anext != &_PyObject_NextNotImplemented);
28552853
}

PC/python3dll.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ EXPORT_FUNC(Py_SetPythonHome)
8686
EXPORT_FUNC(Py_SetRecursionLimit)
8787
EXPORT_FUNC(Py_VaBuildValue)
8888
EXPORT_FUNC(Py_XNewRef)
89-
EXPORT_FUNC(PyAiter_Check)
89+
EXPORT_FUNC(PyAIter_Check)
9090
EXPORT_FUNC(PyArg_Parse)
9191
EXPORT_FUNC(PyArg_ParseTuple)
9292
EXPORT_FUNC(PyArg_ParseTupleAndKeywords)
@@ -443,7 +443,7 @@ EXPORT_FUNC(PyObject_GenericGetAttr)
443443
EXPORT_FUNC(PyObject_GenericGetDict)
444444
EXPORT_FUNC(PyObject_GenericSetAttr)
445445
EXPORT_FUNC(PyObject_GenericSetDict)
446-
EXPORT_FUNC(PyObject_GetAiter)
446+
EXPORT_FUNC(PyObject_GetAIter)
447447
EXPORT_FUNC(PyObject_GetAttr)
448448
EXPORT_FUNC(PyObject_GetAttrString)
449449
EXPORT_FUNC(PyObject_GetItem)

Python/bltinmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ static PyObject *
16101610
builtin_aiter(PyObject *module, PyObject *async_iterable)
16111611
/*[clinic end generated code: output=1bae108d86f7960e input=473993d0cacc7d23]*/
16121612
{
1613-
return PyObject_GetAiter(async_iterable);
1613+
return PyObject_GetAIter(async_iterable);
16141614
}
16151615

16161616
PyObject *PyAnextAwaitable_New(PyObject *, PyObject *);

0 commit comments

Comments
 (0)